105
59

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【2025年6月版】Ubuntu に node.js と npm を入れたい(バージョン管理も)

Last updated at Posted at 2023-04-11

はじめに

Ubuntu22.04, Ubuntu24.04 に node.js と npm を入れたい

image.png

手順

  • とりあえずの node.js と npm をインストール
  • n をインストール(バージョン管理)
  • 安定版の node.js と npm をインストール
  • 最初に入れたとりあえずの node.js と npm をアンインストール
  • 残った node.js と npm が最新であることを確認

とりあえずの node.js と npm をインストール

sudo apt install -y nodejs npm

n をインストール(バージョン管理)

sudo npm install n -g

安定版の node.js と npm をインストール

sudo n stable

最初に入れたとりあえずの node.js と npm をアンインストール

sudo apt purge -y nodejs npm
sudo apt autoremove -y

残った node.js と npm が最新であることを確認

node -v
npm -v

他のバージョンをインストールする/切り替える

sudo n stable		# stable のバージョン
sudo n latest		# latest のバージョン
sudo n ls           # ローカルにあるバージョン
sudo n ls-remote    # リモートから取得できるバージョン
sudo n 22.17.0	    # v22.17.0に切り替え

さいごに

かんたんでしたね

リンク

105
59
4

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
105
59

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?