🌱

【M1 Mac】asdfで古いバージョンのnodeをインストールする方法

2022/10/28に公開

古いプロジェクトをセットアップしようとした際に、node のインストールができず詰まったので、解決した方法を残しておきます。

asdfとは?

多種多様なツールのバージョン管理を可能にするCLIツールです。以前は anyenv 上に nodenv を使っていましたが、PC乗り換えのタイミングで asdf に移行しました。
https://asdf-vm.com/

古いバージョンのnodeをM1 Macにインストールできない

asdf では以下のように node をインストールすることができます。

asdf install nodejs 16.18.0 # 任意のバージョンが指定できます

しかし古いバージョン(今回は 12.18.3 でハマりました)をインストールしようとすると、以下のようなエラーが発生しました。

❯ asdf install nodejs 12.18.3
Trying to update node-build... ok
Downloading node-v12.18.3.tar.gz...
-> https://nodejs.org/dist/v12.18.3/node-v12.18.3.tar.gz

WARNING: node-v12.18.3 is in LTS Maintenance mode and nearing its end of life.
It only receives *critical* security updates, *critical* bug fixes and documentation updates.

Installing node-v12.18.3...

BUILD FAILED (OS X 12.5 using node-build 4.9.95-3-g98f674e2)

Inspect or clean up the working tree at /var/folders/cj/4dl81vz93sz1wgczyt19ln6h0000gp/T/node-build.20221028091622.67284.dIPdqH
Results logged to /var/folders/cj/4dl81vz93sz1wgczyt19ln6h0000gp/T/node-build.20221028091622.67284.log

Last 10 log lines:
make: python: Command not found
make: python: Command not found
make: python: Command not found
make: python: Command not found
make: python: Command not found
make: python: Command not found
make: python: Command not found
make: python: Command not found
Missing or stale config.gypi, please run ./configure
make: *** [config.gypi] Error 1

解決策

筆者の環境ではRosetta経由で実行することで問題を回避できました。

ターミナルを右クリックし「情報を見る」を開きます。

「Rosettaを使用して開く」にチェックを入れてからターミナルを起動します。

ちょろっとオプションが増えていますが、以下を実行することで無事インストールすることができました!

arch -x86_64 asdf install nodejs 12.18.3

参考

https://github.com/asdf-vm/asdf-nodejs/issues/189
https://asdf-vm.com/

Discussion