asdfでNode.jsの複数バージョン管理

asdf プラグイン asdf-nodejs で Node.js の複数バージョンをインストールして管理する方法をご紹介します。

asdf-nodejs

背景 asdf で Node.js のバージョン管理

今まで Node.js のバージョン管理に nvm を使っていたのですが asdf を使い始めた ので nvm から asdf-nodejs へ移行しました。

asdf-nodejs プラグインのインストール

asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git

asdf-nodejs コマンド一覧

asdf list all nodejs

asdf で Node.js の最新版インストール

asdf latest nodejs

18.9.0
asdf install nodejs latest
asdf list

nodejs
  18.9.0
asdf current

nodejs          ______          No version is set. Run "asdf  nodejs "

asdf でグローバル環境で使うバージョンを Node.js 最新版に固定

asdf global nodejs latest
asdf current

nodejs          18.9.0          /Users/your_name/.tool-versions
cat ~/.tool-versions

nodejs 18.9.0

asdf で Node.js LTS のインストール

asdf install nodejs lts
asdf list

nodejs
  16.17.0
  18.9.0
  lts

asdf で現在のディレクトリの Node.js LTS へ固定

asdf local nodejs lts
asdf current

nodejs          lts             /Users/your_name/sample/.tool-versions
cat .tool-versions

nodejs lts

以上、Node.js の複数バージョン管理を nvm から asdf へ移行した、現場からお送りしました。