機械系大学生の修行ログ

sh-lu0's Tech Blog

アイドルが力をくれる

Nodeのバージョンが変わらない

事象

v11.3.0だったのでv12.2.0をインストール

$ nodebrew list
v11.3.0
$ nodebrew install v12.2.0
Fetching: https://nodejs.org/dist/v12.2.0/node-v12.2.0-darwin-x64.tar.gz
######################################################################## 100.0%
Installed successfully

使用するバージョンを変更

$ nodebrew use v12.2.0
use v12.2.0
$ nodebrew list
v11.3.0
v12.2.0

current: v12.2.0

確認

$ node --version
v10.14.1

変わっとらんやないか(;ω;)

Homebrewでインストールしていたのでアンインストール

$ brew uninstall node
Error: Refusing to uninstall /usr/local/Cellar/node/11.10.1
because it is required by yarn, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies node

紐づいているが強制的にアンインストール

$ brew uninstall --ignore-dependencies node
Uninstalling /usr/local/Cellar/node/11.10.1... (4,417 files, 50MB)
$ node --version
v10.14.1

やっぱり変わらない(;ω;)

解決法

nodebrewごと決して再度インストール

nodeをアンインストール

HomebrewでインストールしたNodeをアンインストール
$ brew uninstall node
usr/local/bin/nodeで発見して削除
$ which node
usr/local/bin/node
$ rm -r usr/local/bin/node

再度インストール

nodebrewのインストール
$ brew install nodebrew
$ which nodebrew
/usr/local/bin/nodebrew

setup

$ nodebrew setup
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew

========================================
Export a path to nodebrew:

export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================
Node.jsインストール

既にNode.jsがインストールされていないか確認

$ which node
$ node -v
-bash: node: command not found

インストールして、使用するバージョンを指定

$ nodebrew install v12.2.0
$ nodebrew list
v12.2.0

current: none
$ nodebrew use v12.2.0
use v12.2.0

しかしnodeのバージョンが表示されない

$ node -v
-bash: node: command not found

パスを通して更新

$ echo "export PATH=$HOME/.nodebrew/current/bin:$PATH" >> ~/.bash_profile
$ source ~/.bash_profile
$ which nodebrew
/Users/username/.nodebrew/current/bin/nodebrew

やっとバージョン変更できた!

$ node -v
v12.2.0

参考にしたサイト

ありがとうございます
Nodebrewでnode.jsバージョンを切り替えできなかった時の備忘録 - Qiita
nodebrewでNode.jsをインストールする。 - Qiita