サヨナラanyenv。コンニチハasdf。
今更ながらMac買い換えた勢いで、anyenvを卒業してasdfに乗り換えてみたのでメモ。お仕事用のUbuntu(WSL)も一気に乗り換え。
asdfの良い点
- 使い方が統一されてる。anyenvは*envの使い方をそれぞれ覚えないといけないが、毎回忘れてググるハメに…。
- プラグインがいっぱいある(aws-sam-cliとか、kubectlとか)&その気になれば自分でも簡単に作れそう。
-
.tool-versionsに書いておけばasdf install一発で簡単に同じ構成を再現できる。チームで共有すると便利そう。
asdfのインストール
macOS
-
公式ガイドには"We highly recommend using the official git method."と書いてあるがHomebrewで入れてみた。
-
自分はzshユーザなので、公式サイトでいうZSH & Homebrewパターン。
-
補完用の関数のパスとかがgitで入れた場合と違うので、Ubuntuとシェルの設定を共通にしたい場合はgitで入れるのが無難かもしれない。
brew install coreutils curl git #依存物 brew install asdf
Ubuntu (WSL)
-
Gitでインストール。タグは公式ガイドか、GitHubを見て最新版を使う。
apt install curl git #依存物 git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.12.0
.zshrc
-
頑張ればもうちょい綺麗にかけるかもしれないが、素直にmacOSとそれ以外で分岐。
## Load asdf case "${OSTYPE}" in darwin*) [ -f /opt/homebrew/opt/asdf/libexec/asdf.sh ] && source /opt/homebrew/opt/asdf/libexec/asdf.sh ;; *) [ -f ~/.asdf/asdf.sh ] && source ~/.asdf/asdf.sh esac## Load asdf completions case "${OSTYPE}" in darwin*) [ -d /opt/homebrew/opt/asdf/share/zsh/site-functions ] && fpath=( /opt/homebrew/opt/asdf/share/zsh/site-functions $fpath ) ;; *) [ -d ${ASDF_DIR}/completions ] && fpath=( ${ASDF_DIR}/completions $fpath ) esac autoload -Uz compinit && compinit
Node.jsプラグイン
-
Node.jsのプラグインは公式が提供している。
-
公式ガイドにある通りpost-installフックがある場合があるので、プラグインの依存物を入れる。
-
ちなみに、先にプラグイン入れちゃったけど問題なく動いている模様。
brew install gpg gawk # macOS apt install dirmngr gpg curl gawk # Ubuntu -
nodejsプラグインの追加
-
git-urlを指定して追加するのが推奨らしいが、未指定だと
asdf plugin list allで確認できるurlが使用される模様。% asdf plugin add nodejs ... # Recommendation Prefer the longer git-url method as it is independent of the short-name repo. ...
-
-
バージョンを指定してインストール
-
とりあえず最新版。stableとか指定できたら良いんだが…。
asdf install nodejs latest
-
-
バージョン指定
-
デフォルト(旧global)
asdf set --home nodejs latest # $HOME/.tool-versionsに記録される -
特定ディレクトリ以下 (旧local)
asdf set --parent nodejs latest # $PWD/.tool-versionsに記録される
-
Pythonプラグイン
-
Pythonプラグインの追加
-
danhper/asdf-pythonがデフォルトのようだけど、実際にアクセスするとasdf-community/asdf-pythonにリダイレクトされる。
asdf plugin add python
-
-
バージョンを指定してインストール
asdf install python 3.13.3 -
バージョン指定
asdf set --home python 3.13.3
uvプラグイン
-
uvプラグインの追加
-
uvのプラグインは公式コミュニティが提供している。
asdf plugin add uv
-
-
バージョンを指定してインストール
asdf install uv latest -
バージョン指定
asdf set --home uv latest
Golangプラグイン
-
依存物のインストール。
brew install coreutils # macOS apt install coreutils curl # Ubuntu -
golangプラグインの追加
-
Golangのプラグインは公式コミュニティが提供している。
asdf plugin add golang https://github.com/asdf-community/asdf-golang.git
-
-
インストール&バージョン指定
asdf install golang latest asdf set --home golang latest
Javaプラグイン
-
Javaプラグインの追加
-
halcyon/asdf-javaがインストールされる。
-
公式ではなさそうだけど公式ドキュメントの例に使われていたりもするので信頼できそう(スターも500近い)。
asdf plugin add java
-
-
バージョンを指定してインストール
asdf install java corretto-21.0.7.6.1 -
バージョン指定
asdf set --home java corretto-21.0.7.6.1
その他
-
全プラグインの指定中のバージョンを確認
asdf current -
全プラグインのインストール済みバージョンを確認
asdf list -
各プラグインの利用可能なバージョンを表示
asdf list all <plugin-name> -
特定バージョンのアンインストール
asdf unistall <plugin-name> <version> -
rehash
asdf reshim <plugin-name> -
asdfの全プラグインのアップデート
asdf plugin update --all
Discussion