LoginSignup
30
16

More than 1 year has passed since last update.

【M1 Mac】nodebrew v1.1.0が公式にAppleSiliconに対応したのでNode v16.0.0をインストール

Last updated at Posted at 2021-04-27

はじめに

M1 Mac nodebrewが公式にAppleSiliconに対応したらしい(2021-04-23)
https://github.com/hokaccha/nodebrew/blob/master/History.md#110---2021-04-23

遭遇したエラー

以下のコマンドで簡単にNodeがインストールできるということで、実行してみたところ

$ nodebrew install v16.0.0

なんかたくさんエラーでてる〜〜!!!
対応したちゃうんか〜!!!😂

Fetching: https://nodejs.org/dist/v16.0.0/node-v16.0.0-darwin-arm64.tar.gz
Warning: Failed to create the file 
Warning: /Users/merarli/.nodebrew/src/v16.0.0/node-v16.0.0-darwin-arm64.tar.gz:
Warning:  No such file or directory

curl: (23) Failed writing body (0 != 978)
download failed: https://nodejs.org/dist/v16.0.0/node-v16.0.0-darwin-arm64.tar.gz

理由はわかりませんが、Homebrew経由でnodebrewをインストールしたのが原因っぽい

nodebrew インストール

Homebrew経由のインストールが悪いと思ったので、homebrewでインストールしたnodebrewをアンインストール後、

$ brew rm nodebrew

公式のGitHubに書いてあるcurlコマンドでインストール
https://github.com/hokaccha/nodebrew
初めてインストールする人はここから始めてください

$ curl -L git.io/nodebrew | perl - setup

インストール完了後、以下のパスを~/.zshrcの下部に記述してください。

export PATH=$HOME/.nodebrew/current/bin:$PATH

以下のコマンドで変更した~/.zshrcを再読み込みします。
※ターミナル再起動でもOKです!

$ source ~/.zshrc

以下のコマンドでバージョンを確かめると

$ nodebrew -v

最新のv1.1.0になっていることがわかります。

$ nodebrew -v
nodebrew 1.1.0

Usage:
    nodebrew help                         Show this message
    nodebrew install <version>            Download and install <version> (from binary)
    nodebrew compile <version>            Download and install <version> (from source)
    nodebrew install-binary <version>     Alias of `install` (For backward compatibility)
    nodebrew uninstall <version>          Uninstall <version>
    nodebrew use <version>                Use <version>
    nodebrew list                         List installed versions
    nodebrew ls                           Alias for `list`
    nodebrew ls-remote                    List remote versions
    nodebrew ls-all                       List remote and installed versions
    nodebrew alias <key> <value>          Set alias
    nodebrew unalias <key>                Remove alias
    nodebrew clean <version> | all        Remove source file
    nodebrew selfupdate                   Update nodebrew
    nodebrew migrate-package <version>    Install global NPM packages contained in <version> to current version
    nodebrew exec <version> -- <command>  Execute <command> using specified <version>

node v16.0.0 インストール

nodebrewのインストールが正常に完了したので、次にnode v16.0.0をインストール

$ nodebrew install v16.0.0

以下のような文字が出力されたらインストールが完了します。

Fetching: https://nodejs.org/dist/v16.0.0/node-v16.0.0-darwin-arm64.tar.gz
####################################################################################################################### 100.0%
Installed successfully

以下のコマンドでインストールされたNodeのバージョンを確かめると

$ nodebrew ls

以下のようにでるので、

use v16.0.0

v16.0.0を使用する以下のコマンドを入力

$ nodebrew use v16.0.0

最後にNodeのバージョンを以下のコマンドで確認

$ node -v

以下のようにでれば成功です!

v16.0.0
30
16
2

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
30
16