LoginSignup
125
115

More than 5 years have passed since last update.

MacにNode.js環境を作る(nodebrew)

Posted at

環境

  • Mac OS X 10.11.3
  • zsh

homebrewのnodeモジュールをアンインストール

homebrewのnodebrewがすでに入ってる場合はアンインストール

$ brew uninstall nodebrew
$ brew uninstall node

nodeblewのインストール

nodeblewはnode自体のバージョンを管理するツール。他にも似たようなのでnvmというのがあるらしいけど、zsh使いにはnodebrewの方がいいっぽいので、公式を参考にnodeblewをインストールする。

ソースのダウンロード

$ 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:02 --:--:--     0
  0     0    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0
100 23754  100 23754    0     0   4354      0  0:00:05  0:00:05 --:--:--  4354
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew

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

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

.zshrcにnodebrewのパスを追記

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

設定を再読み込み

$ source ~/.zshrc

これでnodebrewのインストール完了。

Node.jsのインストール

続いてNode.jsをインストールする。

まずはインストール可能なNode.jsを確認。

$ nodebrew ls-remote

現時点での最新stable版はv5.7.0だったのでこれをインストールする。
nodebrewにはバイナリをインストールするnodebrew install-binary <version>という素敵なコマンドが用意されているのでこれを使う。公式もこのコマンドでのインストールを推奨してる。

$ nodebrew install-binary v5.7.0
Fetching: http://nodejs.org/dist/v5.7.0/node-v5.7.0-darwin-x64.tar.gz
######################################################################## 100.0%
Installed successfully

nodeがインストールされていることを確認

$ nodebrew ls
v5.7.0

current: none

使用するnodeのバージョンを指定

$ nodebrew use v5.7.0
use v5.7.0

nodeが使えることを確認

$ node -v
v5.7.0
$ npm -v
3.6.0

これでnode.jsのインストール完了。

125
115
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
125
115