Noriyo Akita's Today I Learned

# 2024-06-01

Table of Contents

2024-06-01

asdf

tl;dr

基本的には公式や他の記事を参考にすると良い 注意点

  • PATH を通す
  • 現在使っているシェルをちゃんと確認する

install

https://qiita.com/ucan-lab/items/0b854cfaa9d7c8ede106

Terminal window
brew install asdf
asdf --version
v0.14.0
echo $SHELL
/bin/bash
# https://asdf-vm.com/guide/getting-started.html#_3-install-asdf
# add path to ~/.bash_profile
Terminal window
asdf install
asdf plugin list all | grep nodejs
nodejs https://github.com/asdf-vm/asdf-nodejs.git
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
asdf list
nodejs
No versions installed
asdf install nodejs latest
Trying to update node-build... ok
Downloading node-v22.2.0-darwin-x64.tar.gz...
-> https://nodejs.org/dist/v22.2.0/node-v22.2.0-darwin-x64.tar.gz
Installing node-v22.2.0-darwin-x64...
Installed node-v22.2.0-darwin-x64 to /Users/noriyo_tcp/.asdf/installs/nodejs/22.2.0
asdf: Warn: You have configured asdf to preserve downloaded files (with always_keep_download=yes or --keep-download). But
asdf: Warn: the current plugin (nodejs) does not support that. Downloaded files will not be preserved.
asdf list
nodejs
22.2.0
asdf local nodejs latest
cat .tool-versions
nodejs 22.2.0

proto を使っていたのでそちらを消す

Terminal window
# proto で管理されている
node -v
v20.10.0
which node
/Users/noriyo_tcp/.proto/bin/node
# reshim してもダメ
asdf reshim nodejs
node -v
v20.10.0
# .bashrc からも proto への参照を消す
# https://moonrepo.dev/docs/proto/install#uninstalling
rm -rf ~/.proto

node が見つからない

Terminal window
node -v
zsh: command not found: node
noriyo_tcp@MacBook-Air ~/M/til main ?
asdf reshim nodejs
noriyo_tcp@MacBook-Air ~/M/til main ?
node -v
zsh: command not found: node
noriyo_tcp@MacBook-Air ~/M/til main ?
which node
node not found

一旦アンインストールしてみる

Terminal window
# 怒られた
asdf uninstall nodejs latest
No such version
asdf list
nodejs
*22.2.0
# version 指定する
asdf uninstall nodejs 22.2.0
asdf list
nodejs
No versions installed

もう1回入れる

Terminal window
asdf install nodejs latest
Trying to update node-build... ok
Downloading node-v22.2.0-darwin-x64.tar.gz...
-> https://nodejs.org/dist/v22.2.0/node-v22.2.0-darwin-x64.tar.gz
Installing node-v22.2.0-darwin-x64...
Installed node-v22.2.0-darwin-x64 to /Users/noriyo_tcp/.asdf/installs/nodejs/22.2.0
asdf: Warn: You have configured asdf to preserve downloaded files (with always_keep_download=yes or --keep-download). But
asdf: Warn: the current plugin (nodejs) does not support that. Downloaded files will not be preserved.
>>> elapsed time 13s
# .tool-version はもうあるので良いっぽい
asdf list
nodejs
*22.2.0
# ダメだなあ

plugin, nodejs を入れ直す

Terminal window
asdf plugin remove nodejs
asdf plugin list
*
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
asdf list
nodejs
No versions installed
# nodejs 入れ直し
asdf install nodejs latest
rm .tool-versions
asdf list
nodejs
22.2.0

PATH を通す

https://asdf-vm.com/guide/getting-started.html#_3-install-asdf

asdf scripts need to be sourced after you have set your $PATH and after you have sourced your framework (oh-my-zsh etc).

$PATH を通さないといけない asdf使ってみた #Node.js - Qiita

Terminal window
# ずっと bash を使っているもんだと思っていたが違うようだぞ?
echo $0
/usr/local/bin/zsh
# これを実行
echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc
# PATH を通す
# at the top of .zshrc
# macOS だと unset だとデフォルトで yes らしいのでコメントアウト
# https://asdf-vm.com/manage/configuration.html#asdf-force-prepend
# export ASDF_FORCE_PREPEND=yes
export PATH=$PATH/.asdf/shims/
echo $PATH
/Users/noriyo_tcp/.asdf/shims:/usr/local/opt/asdf/libexec/bin:/Users/noriyo_tcp/.rbenv/shims:/Users/noriyo_tcp/.rbenv/shims:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/iTerm.app/Contents/Resources/utilities:/Users/noriyo_tcp/.docker/bin:/Users/noriyo_tcp/bin:/bin/.asdf/shims/:/Users/noriyo_tcp/.docker/bin:/Users/noriyo_tcp/bin:/bin
node -v
v22.2.0

Bash & Homebrew (macOS)

https://asdf-vm.com/guide/getting-started.html#_3-install-asdf

~/.bash_profile
echo -e "\n. \"$(brew --prefix asdf)/libexec/asdf.sh\"" >> ~/.bash_profile
echo -e "\n. \"$(brew --prefix asdf)/etc/bash_completion.d/asdf.bash\"" >> ~/.bash_profile
# at the top of ~/.bashrc
export PATH=$PATH/.asdf/shims/
My avatar

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.


More Posts