今回はMacでnode.jsを複数バージョン管理するための「node brew」のインストール方法を紹介しようと思います。
<スポンサードリンク>
1. インストール方法
下記コマンドを使い、インストールする。
$ curl -L git.io/nodebrew | perl - setup
参考実行ログは下記の通り。
$ curl -L git.io/nodebrew | perl - setup % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 100 24634 100 24634 0 0 12564 0 0:00:01 0:00:01 --:--:-- 140k Fetching nodebrew... Installed nodebrew in $HOME/.nodebrew ======================================== Export a path to nodebrew: export PATH=$HOME/.nodebrew/current/bin:$PATH ========================================
2. パスを通す
上記の実行ログの最後にある通り、パスを通す
2-1 ~/.bash_profileがなければ作成する
$ touch ~/.bash_profile
2-2 現状登録されているパスを確認
$ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
2-3 ~/.bash_profileにパスを読み込む処理を追記
$ vim ~/.bash_profile
$ cat ~/.bash_profile export PATH=$HOME/.nodebrew/current/bin:$PATH
2-4 ~/.bash_profileを読み込み
$ source ~/.bash_profile
2-5 再度パスの内容を確認し、nodebrewのパスが追加されていることを確認
$ echo $PATH /Users/<userName>/.nodebrew/current/bin:/Users/<userName>/.nodebrew/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
3. nodebrewのインストール確認
$ nodebrew help nodebrew 1.0.1 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 brewのインストールは終了です。
別記事でnode.jsのインストール方法を紹介しようと思います。