M1 Pro macbook proでarmネイティブのnode v14をインストールしたかった
メモです。
M1 Pro macbook proを購入したため環境構築を進めていたところ、node v14についてはRosettaを使用すれば問題なくインストールできるということで、当初はそちらでインストールしていました。 が、せっかくM1 Proを買ったのにもったいない…。
そう思い調べてみると、どうやらv14.17.0からはapple silicon版がサポートされていたみたいです。
https://github.com/nodejs/node/pull/38051
普通にインストール
$ nvm i v14 Downloading and installing node v14.18.2... Downloading https://nodejs.org/dist/v14.18.2/node-v14.18.2-darwin-arm64.tar.xz... curl: (22) The requested URL returned error: 404 Binary download from https://nodejs.org/dist/v14.18.2/node-v14.18.2-darwin-arm64.tar.xz failed, trying source. grep: /Users/xxx/.nvm/.cache/bin/node-v14.18.2-darwin-arm64/node-v14.18.2-darwin-arm64.tar.xz: No such file or directory Provided file to checksum does not exist. Binary download failed, trying source. Detected that you have 10 CPU core(s) Running with 9 threads to speed up the build Clang v3.5+ detected! CC or CXX not specified, will use Clang as C/C++ compiler! Local cache found: ${NVM_DIR}/.cache/src/node-v14.18.2/node-v14.18.2.tar.xz Checksums match! Using existing downloaded archive ${NVM_DIR}/.cache/src/node-v14.18.2/node-v14.18.2.tar.xz $>./configure --prefix=/Users/xxx/.nvm/versions/node/v14.18.2 < Node.js configure: Found Python 3.8.9... INFO: configure completed successfully /Library/Developer/CommandLineTools/usr/bin/make -C out BUILDTYPE=Release V=0 touch /Users/xxx/.nvm/.cache/src/node-v14.18.2/files/out/Release/obj.target/node_dtrace_header.stamp touch /Users/xxx/.nvm/.cache/src/node-v14.18.2/files/out/Release/obj.target/specialize_node_d.stamp c++ -o /Users/xxx/.nvm/.cache/src/node-v14.18.2/files/out/Release/obj.target/icuucx/deps/icu-small/source/common/uniset.o ../deps/icu-small/source/common/uniset.cpp '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DU_COMMON_IMPLEMENTATION=1' '-DU_ATTRIBUTE_DEPRECATED=' '-D_CRT_SECURE_NO_DEPRECATE=' '-DU_STATIC_IMPLEMENTATION=1' '-DUCONFIG_NO_SERVICE=1' '-DU_ENABLE_DYLOAD=0' '-DU_HAVE_STD_STRING=1' '-DUCONFIG_NO_BREAK_ITERATION=0' -I../deps/icu-small/source/common -O3 -gdwarf-2 -mmacosx-version-min=10.13 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-exceptions -fno-strict-aliasing -MMD -MF /Users/xxx/.nvm/.cache/src/node-v14.18.2/files/out/Release/.deps//Users/xxx/.nvm/.cache/src/node-v14.18.2/files/out/Release/obj.target/icuucx/deps/icu-small/source/common/uniset.o.d.raw -c // 以下めちゃくちゃ長いビルドログ Now using node v14.18.2 (npm v6.14.15)
$ node -v v14.18.2 $ node -p process.arch arm64
ビルド中は初めてCPU使用率が90%を超え、ファンが回っていたので若干不安になりました。
おわり
ちなみに
nvmのgithubを眺めていたところ、homebrew経由でnvm本体をインストールすることが公式にはサポートされていないとのことで、curlでnvmをインストールし直しました。
Homebrew installation is not supported. If you have issues with homebrew-installed
nvm
, pleasebrew uninstall
it, and install it using the instructions below, before filing an issue. https://github.com/nvm-sh/nvm#important-notes
$ brew uninstall nvm $ brew cleanup $ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 14984 100 14984 0 0 56646 0 --:--:-- --:--:-- --:--:-- 58531 => Downloading nvm from git to '/Users/xxx/.nvm' => hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> Initialized empty Git repository in /Users/xxx/.nvm/.git/ => Compressing and cleaning up git repository => nvm source string already in /Users/xxx/.zshrc => Appending bash_completion source string to /Users/xxx/.zshrc => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
homebrew用に構成していた.zshrcを修正します。
$ cat .zshrc export NVM_DIR="$HOME/.nvm" [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && . "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && . "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
↓
$ cat .zshrc export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
$ source .zshrc $ nvm -v 0.39.0