nodebrewでnode.jsの管理

新しいPCでnode.jsを入れ直した際のメモ

nodebrewのインストール

Homebrew経由でnodebrewをインストールしてsetup

$ brew install nodebrew
$ nodebrew setup
You need to manually run setup_dirs to create directories required by nodebrew:
  /usr/local/opt/nodebrew/bin/nodebrew setup_dirs

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

To use Homebrew's directories rather than ~/.nodebrew add to your profile:
  export NODEBREW_ROOT=/usr/local/var/nodebrew

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

 コメントに書かれてる通りに実行してからPATHを通します.

// 実行
$ /usr/local/opt/nodebrew/bin/nodebrew setup_dirs

// pathの追加
$ echo "export PATH=$HOME/.nodebrew/current/bin:$PATH" >> ~/.bash_profile
$ echo "export NODEBREW_ROOT=/usr/local/var/nodebrew" >> ~/.bash_profile 

// .bash_profileの実行
$ source ~/.bash_profile

nodebrewを使う

nodebrewでよく使うコマンドを載せます.

$ nodebrew ls-all // インストールできるバージョンの確認
$ nodebrew install-binary // インストール
$ nodebrew list     // インストールしたバージョンの確認
$ nodebrew use  // バージョンの切り替え

nodebrew install コマンドでもインストールできますが基本的にnodebrew install-binaryのほうで入れたほうがよいそうです.