Nodeのversion管理にはnodebrewを利用させてもらっている。それなりの期間使っているのだが、ふとしたことでHomebrewでもnodebrewがインストールできる事に気がついたので、Homebrew管理とすることにした。
■ 環境
- Mac OSX (10.9.5)
- Homebrew
■ info
nodebrewを確認。
$ brew info nodebrew
nodebrew: stable 0.8.0, HEAD
https://github.com/hokaccha/nodebrew
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nodebrew.rb
==> Caveats
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
$
現時点での最新は”0.8.1“であるようだが、まだ反映されていない様子。
■ install
インストールを実行する。
$ brew instal nodebrew
==> Downloading https://github.com/hokaccha/nodebrew/archive/v0.8.0.tar.gz
######################################################################## 100.0%
==> /usr/local/Cellar/nodebrew/0.8.0/bin/nodebrew setup_dirs
==> Caveats
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 completion has been installed to:
/usr/local/share/zsh/site-functions
==> Summary
/usr/local/Cellar/nodebrew/0.8.0: 7 files, 48K, built in 4 seconds
$
PATHの追加と、”~/.nodebrew”にインストールしたものを入れたくなければ、というのが説明されている。これらはHomebrew管理にしようがしまいが関係ないようである。”~/.bash_profile”にPATHの追加だけしておくことにした。
■ 確認
コマンドがインストールされているか、どのディレクトリで使用されるのかを確認する。
$ which nodebrew
/usr/local/bin/nodebrew
$
$ which node
$ which npm
$
nodeとnpmの2つのコマンドはこの時点ではインストールされていない。
■ node install
せっかくなので最新版をインストールする。インストールには、ソースをダウンロードしてコンパイルする”install“と、コンパイル済みのバイナリをインストールする”install-binary“があるが、今回は”install-binary“でインストールすることにする。
$ nodebrew install-binary v0.12.0
fetch: http://nodejs.org/dist/v0.12.0/node-v0.12.0-darwin-x64.tar.gz
######################################################################## 100.0%
Install successful
$
インストールした後は、コマンドで使用するversionを指定する。
$ nodebrew use v0.12.0
use v0.12.0
$ which node
/Users/withsin/.nodebrew/current/bin/node
$ which npm
/Users/withsin/.nodebrew/current/bin/npm
$
以上。
■ 関連
- Node.js (公式)
- hokaccha/nodebrew (github)
- node関連をupgrade
- nodebrewを新規で入れた時の問題?