anyenv + nodenvで複数バージョンのNode.jsを管理
インストール手順自体は上の記事に従えばいい
fishを使ってるので以下の設定を~/.config/fish/config.fishに以下の設定を追加 code:~/.config/fish/config.fish
if which anyenv
eval (anyenv init - | source)
end
nodeのバージョンを変更
code:sh
nodenv install -l # インストール可能なバージョンを確認
nodenv install 15.4.0
nodenv global 15.4.0 # グローバルなNodeのバージョンをきりかえ
初めnodenv global バージョンを実行しても切り替わらなかった
なんかnodenv rehashしたら以下のエラーがでた
nodenv: cannot rehash: /home/jiro4989/.anyenv/envs/nodenv/shims/.nodenv-shim exists
試しに以下のコマンドで上記ファイルを削除して再実行したら解消した
code:sh
mv /home/jiro4989/.anyenv/envs/nodenv/shims/.nodenv-shim /tmp
nodenv rehash
nodenv global 15.4.0
特定のリポジトリ配下でのみバージョンを切り替えたい場合はlocalを使う
code:sh
nodenv install 12.20.0
nodenv local 12.20.0
node -v # -> v12.20.0
(cd .. && node -v) # -> v15.4.0