nodebrew use しても nodeのバージョンが変わらない事象を解決するまで

nodebrew use しても nodeのバージョンが変わらない事象を解決するまでのメモ

前提

  • fishを利用している
  • nodebrewを利用している(いつ入れたのか忘れた)

結論

  • PATHの設定を見直したら直った

解決までの流れ

$ nodebrew use latest
use v11.5.0

$ node -v
v8.14.1

なぜかnodeのバージョンが切り替わっていない

nodebrewをuninstallする

$ brew uninstall nodebrew
Uninstalling /usr/local/Cellar/nodebrew/1.0.1... (8 files, 38.6KB)
nodebrew 0.9.8 is still installed.
Remove all versions with `brew uninstall --force nodebrew`.

$ brew uninstall --force nodebrew
Uninstalling nodebrew... (8 files, 38.4KB)

$ node -v
v8.14.1

uninstallしたけど、nodeが動作している

$ nodebrew
fish: Unknown command 'nodebrew'

nodebrewは消えている

$ which node
/usr/local/var/nodebrew/current/bin/node

/usr/local/var配下に残っている。なんだろう?

$ echo $fish_user_paths
/usr/local/var/nodebrew/current/bin

いつ設定したんだろう。よく覚えていない。とりあえず消そう。

$ set -e fish_user_paths[100..-1]
$ echo $fish_user_paths

$ node -v
fish: Unknown command 'node'

消したら、nodeへのパスは通らなくなった

$ brew install nodebrew
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> Updated Formulae
cocoapods            haste-client         kontena              mikutter             sphinx-doc           travis               vim@7.4
easyengine           imagemagick          libstfl              ruby                 tox                  vim                  wpscan

==> Downloading https://github.com/hokaccha/nodebrew/archive/v1.0.1.tar.gz
Already downloaded: /Users/yoshito/Library/Caches/Homebrew/downloads/9895acc38dc859a4a1a841cf2e8cd78b519163d3499cdfcd4a08a068ce0babcd--nodebrew-1.0.1.tar.gz
==> Caveats
You need to manually run setup_dirs to create directories required by nodebrew:
  /usr/local/opt/nodebrew/bin/nodebrew setup_dirs

Add path:
  export PATH=$HOME/.nodebrew/current/bin:$PATH

To use Homebrew's directories rather than ~/.nodebrew add to your profile:
    export NODEBREW_ROOT=/usr/local/var/nodebrew

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/nodebrew/1.0.1: 8 files, 38.6KB, built in 7 seconds

いろいろ書かれてる。言われてるとおりにやろう。

$ node -v
fish: Unknown command 'node'

まだPATH通してないので当然か

$ set -U fish_user_paths $fish_user_paths ~/.nodebrew/current/bin
$ node -v
v11.5.0
$ nodebrew use 8.14.1
use v8.14.1
$ node -v
v8.14.1
$ nodebrew use latest
use v11.5.0

ちゃんと切り替わるようになった。めでたしめでたし