LoginSignup
41
24

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

Last updated at Posted at 2023-04-11

はじめに

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

手順

  • とりあえずの 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 18.15.04	# v18.15.0

さいごに

かんたんでしたね

41
24
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
41
24