2つの原因が重なっていて解決まで時間食ってしまったので、メモ。
方法:Doctorコマンドを使いながら対応していく
Doctorコマンド
curl -fsSL https://github.com/nodenv/nodenv-installer/raw/master/bin/nodenv-doctor | bash
nodenvのバージョン
nodenv -v
nodenv 1.4.1
nodenv init
ができてない
セットアップのときにしたはずなんだが、と思いながら指示されているので nodenv init
しました。ちょいモヤ。
Checking for `nodenv' in PATH: /opt/homebrew/bin/nodenv
Checking for nodenv shims in PATH: not found
The directory `/Users/your-name/.nodenv/shims' must be present in PATH for nodenv to work.
Please run `nodenv init' and follow the instructions.
Checking `nodenv install' support: /opt/homebrew/bin/nodenv-install (node-build 5.3.14)
Counting installed Node versions: 24 versions
Auditing installed plugins: OK
opt/homebrew/bin
より前にPATHを設定している
Checking for `nodenv' in PATH: /opt/homebrew/bin/nodenv
Checking for nodenv shims in PATH: found at wrong position
The directory `/Users/your-name/.nodenv/shims' is present in PATH, but is listed too late.
The Node version found in `/opt/homebrew/bin' will have precedence. Please reorder your PATH.
Checking `nodenv install' support: /opt/homebrew/bin/nodenv-install (node-build 5.3.14)
Counting installed Node versions: 24 versions
Auditing installed plugins: OK
node -v
すると v23
という新しめのバージョンが出て、はて?どこかでインストールしたっけと思いつつ色々しらべてると、
「herokuのCLIツールをインストールした際にグローバルにnodeがインストールされていた」
zshrc
の書き方も相まってnodenvより先にグローバルのnodeが使われてしまう状況になっていました。
以下のように brew install されたnodeより前にPATHを追加するように対応しました。
- # NODENV
- export PATH="$HOME/.nodenv/shims:$PATH"
- eval "$(rbenv init - zsh)"
export PATH="/opt/homebrew/bin:$PATH"
+ # NODENV
+ export PATH="$HOME/.nodenv/shims:$PATH"
+ eval "$(rbenv init - zsh)"
.nodenv/bin
と説明されているサイトが多かったですが、どこかのバージョンから .nodenv/shims
に切り替わってそうです(詳細未調査)
チェックOK
Checking for `nodenv' in PATH: /opt/homebrew/bin/nodenv
Checking for nodenv shims in PATH: OK
Checking `nodenv install' support: /opt/homebrew/bin/nodenv-install (node-build 5.3.14)
Counting installed Node versions: 24 versions
Auditing installed plugins: OK