Node.jsの管理はnodebrewが楽なのでnodebrewを使いましょう。
nodebrewはhomebrewでインストールします。
Homebrewのインストール
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
nodebrewのインストール
インストール可能なバージョンを確認する
$ nodebrew ls-remote
インストール
今回はv8を入れたいと思います。
以下で8の最新を入れます
$ nodebrew install-binary v8
Installed successfully
インストールできてるか確認
$ nodebrew ls
v8.11.2
current: none
使うバージョンを指定する
$ nodebrew use v8
use v8.11.2
インストールが終わったら環境変数の設定をする。
$ vi .bash_profile
.bash_profile
に以下を書き込む。
export PATH=$PATH:$HOME/.nodebrew/current/bin
.bash_profile
再読み込み
$ source .bash_profile
Node.jsのインストール
環境変数を設定したらnodebrewが使えるようになるので、早速Node.jsをインストールしましょう。
バージョンは安定版(stable)のインストールがおすすめです。
$ nodebrew install-binary stable
nodebrew use
で、使うバージョンを切り替えます。
$ nodebrew use stable