LoginSignup
20
17

More than 1 year has passed since last update.

[m1]asdfでバージョン管理を行なったnodejsを使うまで[mac]

Last updated at Posted at 2021-05-27

asdfとは

いろんな言語のバージョン管理がまとめてできるやつ(雑)
類似ツール: anyenv

環境

  • MacBook Air (M1, 2020)

asdf

% brew install asdf

zshを使ってるので以下を実行

% echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc

node

準備

% brew install gpg gawk
% asdf plugin-add nodejs 

インストール可能なバージョンの確認

% asdf list all nodejs

最新安定板の確認/インストール

% asdf latest nodejs
16.2.0
% asdf install nodejs latest

バージョン指定の場合はこっち

バージョンは適当な例

% asdf install nodejs 12.22.1

インストールしてあるバージョンの一覧確認

% asdf list
nodejs
  16.2.0
% asdf list nodejs
  16.2.0

とりあえずのプライマリバージョン設定

% asdf global nodejs 16.2.0

有効なバージョンの確認

% asdf current
nodejs          16.2.0          /Users/ユーザー名/.tool-versions
% asdf current nodejs
nodejs          16.2.0          /Users/ユーザー名/.tool-versions
% cat ~/.tool-versions
nodejs 16.2.0
% node -v
v16.2.0

globalやらlocalやら叩くと各所に .tool-versions ってファイルができてそこに記録されるらしい
gitとかで管理すれば環境構築の時とかバージョンはそこ見てねとかで済みそう

適当にファイル作って実行してみる

% touch test.js
test.js
console.log("hello world");
% node test.js
hello world
20
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
17