Node.jsのインストールをまとめてみました。
「nodebrew」インストール
「Homebrew」を使って「nodebrew」をインストールします。
$ brew install nodebrew
「nodebrew」コマンド確認
インストール後に「nodebrew」コマンドが使用できるか確認します。
$ nodebrew 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> Example: # install nodebrew install v8.9.4 # use a specific version number nodebrew use v8.9.4
「Node.js」インストール
以下のコマンドを実行して最新版の「Node.js」をインストールします。
$ nodebrew install-binary latest
「Node.js」のバージョン確認
以下のコマンドを実行してバージョンを確認します。
$ nodebrew ls v16.1.0 current: none
「current: none」になっているので、インストールしたバージョンを有効化します。
$ nodebrew use v16.1.0 use v16.1.0
もう一度「nodebrew ls 」を実行して「v16.1.0」セットされたことを確認します。
nodebrew ls v16.1.0 current: v16.1.0
パスの追加
パスが通ってないので、パスを追加します。
vi ~/.zshrc
以下のコマンドを追加します。
export PATH=$HOME/.nodebrew/current/bin:$PATH
コマンド確認
- 「node」コマンド確認
$ node -v v16.1.0
- 「npm」コマンド確認
$ npm -v 7.11.2