0
0

More than 3 years have passed since last update.

CentOS 7 で Node.js(バイナリアーカイブ)を使えるようにする方法

Posted at

環境

  • Windows10 + Virtual Box + CentOS 7
  • VScode + Remote-SSH

ソース入手

下記のページからダウンロードする。今回は、Linux Binaries (x64) を選択。
nodejs download page
ダウンロードした node-v14.17.5-linux-x64.tar.xz を /root に移動

解凍と配置

# tar -xJvf node-v14.17.5-linux-x64.tar.xz -C /usr/local/lib/
# cd /usr/local/lib/
# ln -s node-v14.17.5-linux-x64/ nodejs

パスを通す

/etc/profile を編集してもよさそうだが、記述が煩雑になりそうだったので .bash_profile を編集することにする。

# vi ~/.bash_profile
...
PATH=$PATH:/usr/local/lib/nodejs/bin
export PATH
(ZZ)
# source .bash_profile
# node -v
v14.17.5

上記の方法は、個別ユーザーごとに /home/[user]/.bash_profile の編集が必要。

nodejs をバージョンアップする

目的のバージョンのバイナリアーカイブを入手して 解凍、/usr/local/lib/ に配置して、シンボリックリンクを張り替える。

# cd /usr/local/lib/
# rm nodejs ← rm nodejs/ 末尾にスラッシュがあるとリンク先まで削除してしまうので注意
# ln -s node-[v14.17.5]-[linux-x64]

削除

パスの記述を削除する

# vi ~/.bash_profile
...
PATH=$PATH:/usr/local/lib/nodejs/bin ← この行を削除
export PATH
(ZZ)
# source .bash_profile

ディレクトリを削除する

# cd /usr/local/lib/
# rm -rf node-v14.17.5-linux-x64
# rm nodejs

まとめ

シンボリックリンクは使える!(ネストしない限り)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0