[Node.js] バージョン管理ツール nodebrew を Mac にインストールする方法

Node.js のバージョン管理ツール nodebrew を Mac にインストールする方法をご紹介します。

hokaccha/nodebrew · GitHub

nodebrew のインストール

% curl https://raw.github.com/hokaccha/nodebrew/master/nodebrew | perl - setup

.zshrc や .bashrc に下記を追記する。

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

リロード

% source ~/.bashrc

正常にインストールできたか確認する

% nodebrew help

あとは Node.js をインストールするだけ。

% nodebrew stable

しかし、色々とハマった場合は、以降の内容を参考にして下さい。

error: could not configure a cxx compiler!

% nodebrew install v0.6.21
fetch: http://nodejs.org/dist/v0.6.21/node-v0.6.21.tar.gz
######################################################################## 100.0%
Checking for program g++ or c++          : not found 
/Users/your_username/.nodebrew/src/node-v0.6.21/wscript:273: error: could not configure a cxx compiler!

gcc をインストールする。
kennethreitz/osx-gcc-installer · GitHub

Checking for openssl : not found

openssl がインストールされているのに Checking for openssl : not found となる問題は、pkg-config をインストールすることで解決します。

% brew install pkg-config

Build failed: -> task failed (err #2)

下記のようなエラーで Node.js をインストールできない場合、Command Line Tools がインストールしていないのが原因なので、インストールする。

% nodebrew install v0.6.21
...(省略)...
make[1]: *** [src/unix/darwin.o] Error 1
Waf: Leaving directory `/Users/your_username/.nodebrew/src/node-v0.6.21/out'
Build failed:  -> task failed (err #2): 
    {task: uv uv.h -> uv.a}
make: *** [program] Error 1

Command Line Tools は、

Xcode -> Preferences -> Downloads -> Command Line Tools

からインストールできます。

以上、Node.js のバージョン管理ツール nodebrew を Mac にインストールした、現場からお送りしました。

参考情報