LoginSignup
100
103

More than 5 years have passed since last update.

Node.jsのバージョンを管理する

Last updated at Posted at 2015-12-30

バージョンアップしたい時とか、上げたら不具合出たとか、プロジェクトによって使いたいバージョンが違うなんて時はどうしましょうという時のために各OS別のメモ。

Node.js公式サイトのパッケージは直接インストールせずバージョン管理ツールを利用する。

Linux / nvm

デフォルトだと~/.nvm/にインストールされるので変更したい場合はgithubのREADME参照。

インストール

githubで最新版を確認すること。

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

使い方

利用できるnode.jsのバージョンを見てみると、全てのバージョンがズラ~っと出る。

$ nvm ls-remote
        v0.1.14
        v0.1.15

        .
        .
        .

         v4.2.4
         v5.0.0
         v5.1.0
         v5.1.1
         v5.2.0
         v5.3.0

入れたいバージョン選んでインストールする。npmも勝手に入る。

$ nvm install 4.2.4
Downloading https://nodejs.org/dist/v4.2.4/node-v4.2.4-linux-x64.tar.xz...
######################################################################## 100.0%
WARNING: checksums are currently disabled for node.js v4.0 and later
Now using node v4.2.4 (npm v2.14.12)
$ nvm install 5.3.0
Downloading https://nodejs.org/dist/v5.3.0/node-v5.3.0-linux-x64.tar.xz...
######################################################################## 100.0%
WARNING: checksums are currently disabled for node.js v4.0 and later

なんかWARNING出てる( ˙-˙ )

現在のバージョンを確認してみる。

$ node -v
v5.3.0
$ npm -v
3.3.12

インストールしたNode.jsのバージョンはnvm lsで見れる。

$nvm ls
         v4.2.4
->       v5.3.0
node -> stable (-> v5.3.0) (default)
stable -> 5.3 (-> v5.3.0) (default)
iojs -> N/A (default)

バージョンを指定して切り替える事ができる。npmも同時に切り替わる。

$ nvm use 4.2.4
Now using node v4.2.4 (npm v2.14.12)
$ node -v
v4.2.4
$ npm -v
2.14.12

ログインするたびにバージョン指定しないといけないのでデフォルトのバージョンを指定する。

$ nvm alias default 5.3.0

ちなみに、iojsというのはv0.12からforkして別途開発が行われていたプロジェクトで、Node.js v4で統合されました。

Mac / nodebrew

nvmと大体同じ。

インストール

既に入ってたらアンインストールしておきましょう。

brewでインストールしてたら

$ brew uninstall node

本家のNode.jsをインストールしてたら

$ curl -ks https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh | bash

nodebrewインストール

$ curl -L git.io/nodebrew | perl - setup
$ export PATH=$HOME/.nodebrew/current/bin:$PATH
$ source ~/.bashrc

使い方

インストール可能なバージョンを確認

$ nodebrew ls-remote

指定バージョンをダウンロード

$ nodebrew install-binary 4.2.4

ダウンロードしたバージョンを確認

$ nodebrew ls

切り替え

$ nodebrew use 4.2.4

Windows / nodist

Windowsにもあるんですね。使い勝手は大体同じ。

インストール

githubにインストーラのリンクがあるので、それでインストールできる。

使い方

インストール可能なバージョンを確認

> nodist dist

指定バージョンをダウンロード

> nodist add 5.3.0

ダウンロードしたバージョンを確認

> nodist ls

切り替え

> nodist use 5.3.0

各ツールの詳しい使い方は本家のサイトの方を参照して下さい。

100
103
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
100
103