LoginSignup
0
0

Macを買い換えたのでNode.jsをasdfで入れるまでをやってみた。(備忘録)

Posted at

m2にしたぞ!ばんざーい!!

というわけでbrewのインストールからasdfでnode.jsをバージョン管理するまで。
ちなみにintelでも同様。

asdfのいいところ
バージョン管理ツールは他にも色々あるが、
asdfはnodeに限らずいろんなものをバージョン管理できる。
(nodenvなどはnodeしか管理できなかったり更新されていなかったりするのでasdfがより使われるツールになってきているのだとか。)

brewのインストール

https://brew.sh/ja/
に書いてあるコマンドをコピペ

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

入れればzshでも普通にインストールできる。

zshの中でbashを動かしているらしい。知らんけど。

その際に

- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/mappi/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

と出てきたので

 (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/mappi/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

してbrew helpでインストールを確認する。
参考:
https://aiacademy.jp/media/?p=2817

asdfのインストール

https://asdf-vm.com/guide/getting-started.html
のサイトの手順で実行。
↑のサイトに他のやり方も書いてあるけど
以下はMacでzsh(標準装備)のターミナルでbrewを使ったインストールになります。

brew install coreutils curl git

して

brew install asdf

先ほどの参考サイトを見ながら

echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc
brew install gpg gawk
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git

まずは最新版をasdfにインストール

asdf install nodejs latest

ちなみにこの状態でnode -vとかしても何も出てこないのですが、
ターミナルを再起動すると

No version is set for command node
Consider adding one of the following versions in your config file at 
nodejs 20.8.0

となり、asdfでのnodeを入れる準備は整いました。
(asdf instalの段階ではnodeは入らない。)
別バージョンが欲しい時は
欲しいnodeをまずインストールして(この時は12.0.0が必要だった)

asdf install nodejs 12.0.0

そしたらいよいよnodeを入れていくのですが
ローカル反映だと
そのファイル等のレポジトリに移動した後、

asdf local nodejs 12.0.0

とすれば、そのファイルのみnode.jsの指定のバージョンが適用される。
これでいろんなファイルに別バージョンのnodeをそれぞれに適用することが可能!🎉

ちなみに、globalでパソコン全体に入れたい時は

asdf global nodejs latest

latest(最新版)またはasdfであらかじめインストールした指定のバージョンにすればOK!

0
0
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
0
0