LoginSignup
42
42

More than 5 years have passed since last update.

MacにNode.jsをインストールする

Last updated at Posted at 2014-06-30

環境:Mac OS X Version 10.9.3

Node.jsはNode.js日本ユーザーグループはからダウンロードしてインストールできる。
ただ、Node.jsはバージョンアップが早いのでNVM(Node Version Manager)を使用してNode.jsのバージョン管理を行うことがおススメ。

1.nvmをインストールする

GitHubのnvmリポジトリを見ると、インストール方法は2通りある。
1.Install Script
2.Manual Install

今回はInstall Scriptを使用したインストールを選択。

$ curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | sh

or

$ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | sh

を実行する。

$ curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3047  100  3047    0     0   4760      0 --:--:-- --:--:-- --:--:--  4753
=> Downloading nvm from git to '/Users/username/.nvm'
=> Cloning into '/Users/username/.nvm'...
remote: Counting objects: 1541, done.
remote: Compressing objects: 100% (762/762), done.
remote: Total 1541 (delta 789), reused 1502 (delta 762)
Receiving objects: 100% (1541/1541), 281.79 KiB | 158.00 KiB/s, done.
Resolving deltas: 100% (789/789), done.
Checking connectivity... done.

=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile.
=> Create one of them and run this script again
   OR
=> Append the following lines to the correct file yourself:

export NVM_DIR="/Users/username/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
=> Close and reopen your terminal to start using nvm

~/.nvmディレクトリが作成されます。

このままではnvmコマンドを実行しても、command not foundになるので、.bash_profileを作成し次の記述を追加する。

$ vi .bash_profile
.bash_profile
# nvm設定
[[ -s ~/.nvm/nvm.sh ]] && . ~/.nvm/nvm.sh
nvm use default
npm_dir=${NVM_PATH}_modules
export NODE_PATH=$npm_dir

更新を反映させるために、一旦シェルを抜けるか、次のコマンドを入力して、設定を反映させる

$ source ~/.bash_profile
N/A version is not installed yet

「N/A version is not installed yet」と表示されるが、これはまだデフォルトで使用するNode.jsが設定されていないだけなので、とりあえず無視。

気になるのであれば、先に下のコマンドを実行しておく。

$ nvm alias default v0.10.12

nvmが使えるか確認する。

$ nvm --version
0.10.0

2.Node.jsをインストールする

インストール可能なNode.jsのバージョンを確認する。

$ nvm ls-remote
     v0.1.14
     v0.1.15
     v0.1.16
:
:
    v0.11.12
    v0.11.13

今回は最新のv0.11.13をインストールする。

$ nvm install v0.11.13
######################################################################## 100.0%
Now using node v0.11.13

3.Node.jsを実行する

$ nvm use v0.11.13
Now using node v0.11.13
42
42
1

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
42
42