LoginSignup
3
0

More than 1 year has passed since last update.

Nodeバージョン管理ツール「n」でバージョンが切り替わらない

Posted at

困った内容

n コマンドを使ってもバージョンが変わっていない

  • コマンド
コマンド
sudo npm install -g n
n -V
n --stable
sudo n stable
node -v
  • 実行例
実行例
$ sudo npm install -g n
...省略
$ n -V
v9.0.1
$ n --stable
18.12.1
$ sudo n stable
     copying : node/18.12.1
   installed : v18.12.1 (with npm 8.19.2)
$ node -v
v12.22.12 // 変わってない

原因

which node~/.bash_profile の記載が異なる

  • コマンド
コマンド
which node
cat ~/.bash_profile
  • 実行例
実行例
$ which node
/usr/local/bin/node
$ cat ~/.bash_profile
PATH="$HOME/bin:$HOME/.local/bin:$PATH"

対処法

~/.bash_profile の記載を変更する

  • コマンド
コマンド
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
node -v
  • 実行例
実行例
$ echo 'export PATH=$HOME/bin:$PATH' >> ~/.bash_profile
$ source ~/.bash_profile
$ node -v
v18.12.1 // 変わっている

参考文献

3
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
3
0