LoginSignup
19
25

More than 5 years have passed since last update.

Debian9 (stretch) に Node.js をインストールする

Last updated at Posted at 2018-06-02

Debianのパッケージマネージャー(apt)でインストールする方法

ドキュメント

パッケージマネージャを利用した Node.js のインストール | Node.js https://nodejs.org/ja/download/package-manager/

インストール手順

最新版(stable)

$ curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
$ sudo apt-get install -y nodejs

インストール後のNode.jsとnpmのバージョン(2018年6月2日)

$ nodejs -v
v10.3.0

$ npm -v
6.1.0

推奨版(LTS)

$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt-get install -y nodejs

NVMを使って複数バージョンのNode.jsをインストールする方法

ドキュメント

Installing node js using nvm http://blog.mobnia.com/installing-node-with-nvm-on-a-debian-server/

インストール手順

インストール、インストール後のNVM動作チェック、NVMを使ってNode.jsをインストールする手順です。インストールされるNode.jsは、LTS(推奨版)ではなく最新版になります。

$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
$ command -v nvm
$ nvm install node

バージョンを指定してインストール、有効化、アンインストールする方法

$ nvm install v6.14.2  
$ nvm use v6.14.2
$ nvm uninstall v6.14.2

NVMコマンドの使用

Node.jsのインストール

$ nvm install node
Downloading and installing node v10.3.0...
Downloading https://nodejs.org/dist/v10.3.0/node-v10.3.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.3.0 (npm v6.1.0)
Creating default alias: default -> node (-> v10.3.0)

Node.jsのインストールパス確認

$ which node
/home/username/.nvm/versions/node/v10.3.0/bin/node

実行されるNode.jsのバージョンの確認

$ nvm use node
Now using node v10.3.0 (npm v6.1.0)

stable(最新版)のインストール(最新のリリース版がインストールされます)

$ nvm install stable
v10.3.0 is already installed.
Now using node v10.3.0 (npm v6.1.0)

LTS版のインストール(推奨版がインストールされます)

$ nvm install --lts
Installing latest LTS version.
Downloading and installing node v8.11.2...
Downloading https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v8.11.2 (npm v5.6.0)

$ node -v
v8.11.2

stable(最新版)をデフォルトのバージョンに設定する。

$ nvm alias default stable
default -> stable (-> v10.3.0)

$ nvm use stable
Now using node v10.3.0 (npm v6.1.0)

$ nvm use node
Now using node v10.3.0 (npm v6.1.0)

$ node -v
v10.3.0

$ npm -v
6.1.0

LTS(推奨版)をデフォルトのバージョンに設定する。

$ nvm alias default lts/*
default -> lts/* (-> v8.11.2)

$ node -v
v10.3.0

動作しているNode.jsのバージョン確認

$ nvm run node --version
Running node v10.3.0 (npm v6.1.0)
v10.3.0

インストールされているNode.jsバージョンの確認

$ nvm which 10.3.0
/home/username/.nvm/versions/node/v10.3.0/bin/node

$ nvm which 8.11.2
/home/username/.nvm/versions/node/v8.11.2/bin/node

$ ls -l /home/username/.nvm/versions/node/
合計 8
drwxr-xr-x 6 user group 4096  6月  2 21:09 v10.3.0
drwxr-xr-x 7 user group 4096  6月  2 21:12 v8.11.2

Node.jsのバージョンを指定して実行する。

$ nvm exec v8.11.2 node --version
Running node v8.11.2 (npm v5.6.0)
v8.11.2

$ nvm use v8.11.2
Now using node v8.11.2 (npm v5.6.0)

$ node -v
v8.11.2

Node.jsのデフォルトバージョンを変更する。

$ nvm alias default  v8.11.2
default -> v8.11.2

$ node -v
v8.11.2

$ nvm --version
0.33.11

$ node --version
v8.11.2

インストールできるバージョンの確認

$ nvm ls-remote
        v0.1.14
        v0.1.15
        v0.1.16
(中略)
        v6.14.1   (LTS: Boron)
        v6.14.2   (Latest LTS: Boron)
(中略)
        v8.11.1   (LTS: Carbon)
->      v8.11.2   (Latest LTS: Carbon)
(中略)
        v10.2.1
        v10.3.0
19
25
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
19
25