nodebrew とは
nodebrew は複数のバージョンの Node.js を管理できるツール。
Node.js version manager.
hokaccha/nodebrew · GitHub
今回の環境
MacBook Air + Mac OS X Yosemite 10.10.2
$ uname -mrsv
Darwin 14.1.0 Darwin Kernel Version 14.1.0: Thu Feb 26 19:26:47 PST 2015; root:xnu-2782.10.73~1/RELEASE_X86_64 x86_64
Homebrew を使って nodebrew をインストール
Homebrew は、 Mac OS X にいろいろなソフトをインストールできる便利なツール。
HomebrewはAppleが用意していないあなたが必要なものをインストールします。
Homebrew — OS X用パッケージマネージャー
Homebrew を使って、 nodebrew をインストールする。
$ brew search nodebrew
nodebrew
$ brew install 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 3 seconds
インストールした nodebrew を起動。
$ nodebrew
nodebrew 0.8.0
Usage:
nodebrew help Show this message
nodebrew install <version> Download and install a <version> (compile from source)
nodebrew install-binary <version> Download and install a <version> (binary file)
nodebrew uninstall <version> Uninstall a 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> <version> Set alias to version
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> specified <version>
Example:
# install from binary
nodebrew install-binary v0.10.22
# use a specific version number
nodebrew use v0.10.22
# io.js
nodebrew install-binary io@v1.0.0
nodebrew use io@v1.0.0
Node.js を使うためのパスの設定
.bashrc や .zshrc に以下を追加する、と公式ドキュメントには書いてある。
export PATH=$HOME/.nodebrew/current/bin:$PATH
自分は .bash_profile に追加した。
source コマンドで設定を反映させる。
$ source ~/.bash_profile
複数の Node.js をインストールする
インストール可能な Node.js のバージョン一覧と、インストール済みのバージョンを表示する。
$ nodebrew ls-all
remote:
v0.0.1 v0.0.2 v0.0.3 v0.0.4 v0.0.5 v0.0.6
(中略)
v0.12.0
io@v1.0.0 io@v1.0.1 io@v1.0.2 io@v1.0.3 io@v1.0.4
(中略)
io@v1.5.0 io@v1.5.1
local:
not installed
current: none
安定版をインストールしてみる。
$ nodebrew install-binary stable
fetch: http://nodejs.org/dist/v0.12.0/node-v0.12.0-darwin-x64.tar.gz
######################################################################## 100.0%
Install successful
バージョン 0.10.29 をインストールしてみる。
$ nodebrew install-binary v0.10.29
fetch: http://nodejs.org/dist/v0.10.29/node-v0.10.29-darwin-x64.tar.gz
######################################################################## 100.0%
Install successful
nodebrew では Node.js の複数のバージョンをインストールしておいて、必要に応じて切り替えることが可能。
バージョン 0.10.29 を使うように設定。
$ nodebrew use v0.10.29
use v0.10.29
$ nodebrew ls
v0.10.29
v0.12.0
current: v0.10.29
Node.js はホームディレクトリの .nodebrew ディレクトリ以下にインストールされる。
$ which node
/Users/alice/.nodebrew/current/bin/node
$ node --version
v0.10.29
tags: node.js
Posted by NI-Lab. (@nilab)