LoginSignup
41
32

More than 5 years have passed since last update.

nodebrewでnode.jsのバージョン切り替え

Last updated at Posted at 2016-02-16

nodebrewとは

node.jsのバージョン管理ツール。
複数バージョンを切り替えて使うことができる。
他にもnvmnbenvがある。

npmはnodeのモジュール管理ツール。

インストールの前に

既にnodeがインストール済みの場合、アンインストールする必要がある。

homebrewでインストールした場合

$ brew uninstall node

pkgでインストールした場合

  • 下記のスクリプトをファイルなりに記載して実行する
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \
| while read i; do
  sudo rm /usr/local/${i}
done
sudo rm -rf /usr/local/lib/node \
     /usr/local/lib/node_modules \
     /var/db/receipts/org.nodejs.*
  • npmコマンドでインストールしたグローバルモジュールも削除
$ sudo rm -rf ~/.npm

nodebrewインストール

下記のコマンド1行でインストールできる。

$ curl -L git.io/nodebrew | perl - setup
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0
100 23752  100 23752    0     0   4928      0  0:00:04  0:00:04 --:--:-- 29072
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew

========================================
Export a path to nodebrew:

export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================
  • 画面出力に従ってパスを追加

環境によって、.zshrcなり.bashrcにパスを追加する

$ vi ~/.zshrc
export PATH=$HOME/.nodebrew/current/bin:$PATH
  • 動作確認
$ source ~/.zshrc
$ nodebrew help

node.jsインストール

最新版をインストール
$ nodebrew install latest
安定版をインストール
$ nodebrew install stable
バージョン指定でインストール
$ nodebrew install v0.11.13
  • 使うバージョンを指定
latest
$ nodebrew use latest
stable
$ nodebrew use stable
バージョン指定
$ nodebrew use v0.11.13
  • バージョン確認
$ node -v
$ npm -v
41
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
41
32