Ubuntu/Debianに最新のNode.jsをインストールする一番良い方法

Linuxガイド

UbuntuとDebianに最新リリース版のNode.jsをインストールする方法を紹介します。Node.jsはV8 JavaScriptエンジンで動作するJavaScript実行環境です。オープンソースであり、様々なプラットフォーム(Linux・ Windows・macOS)で動作します。

NodeSourceのレポジトリからインストール

レポジトリの追加

大抵の環境にはインストールされていますが、もし「curl」コマンドがインストールされていなければ以下のコマンドでインストールします。

sudo apt install -y curl

最新リリース版は、以下のコマンドでインストールできます(本記事公開時点でv14)。

# Ubuntuの場合 / Debianでsudoを使う場合
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

# Debianでrootを使う場合
curl -sL https://deb.nodesource.com/setup_lts.x | bash -
apt install -y nodejs

最新LTS版(長期サポート版)は、以下のコマンドでインストールできます(本記事公開時点でv12)。

# Ubuntuの場合 / Debianでsudoを使う場合
curl -sL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt install -y nodejs

# Debianでrootを使う場合
curl -sL https://deb.nodesource.com/setup_current.x | bash -
apt install -y nodejs

バージョン番号を指定してインストールすることもできます。

v14.x:

# Ubuntuの場合 / Debianでsudoを使う場合
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt install -y nodejs

# Debianでrootを使う場合
curl -sL https://deb.nodesource.com/setup_14.x | bash -
apt install -y nodejs

v12.x:

# Ubuntuの場合 / Debianでsudoを使う場合
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install -y nodejs

# Debianでrootを使う場合
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt install -y nodejs

v10.x:

# Ubuntuの場合 / Debianでsudoを使う場合
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install -y nodejs

# Debianでrootを使う場合
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt install -y nodejs

ネイティブ拡張(native addon)をビルドする場合は、以下のコマンドで「build-essential」パッケージもインストールしておきましょう。

# Ubuntuの場合 / Debianでsudoを使う場合
sudo apt install -y build-essential

# Debianでrootを使う場合
apt install -y build-essential

snapでインストール

以下のコマンドを実行して、snapパッケージでNode.jsをインストールすることもできます。Ubuntuの場合、デフォルトでsnapパッケージのインストールが可能です。本記事公開時点では、LTS版であるv12がインストールされます。

sudo snap install node --classic

他のディストリビューションでも、snapをセットアップすれば同じコマンドでインストールできます。

なお、以下のように「–edge」オプションを追加すると開発中のバージョンがインストールされます(本記事公開時点でv15)。開発中バージョンは通常の利用には向かないので注意が必要です。

sudo snap install node --classic --edge
Linuxガイド
\シェアお願いします/
LFI

コメント

タイトルとURLをコピーしました