DEV Community

Borikatsu
Borikatsu

Posted on

Ubuntuにnode入れてバージョン管理

Ubuntu に nodejs と npm と yarn 入れる。
node と npm は n でバージョン管理する。

会社の PC 設定する時に毎回調べたり、個人 PC の設定忘れがちなのでメモとして。


目次


やること

  1. n をインストールするためのテンポラリな node と npm をインストール
  2. n をインストールする
  3. node/npm を n で再インストール
  4. テンポラリな node と npm を削除
  5. yarn をインストール

れっつごー


n をインストールするまで

# pkgマネージャーからnode/npmをインストール(テンポラリ利用)
$ sudo apt install -y nodejs npm

# n をインストール
$ sudo npm install n -g
Enter fullscreen mode Exit fullscreen mode

node/npm を再インストール

# 安定バージョン
$ sudo n stable

# 最新バージョン
$ sudo n latest

# バージョン指定
## リモートのバージョン確認
$ sudo n ls-remote | head
Listing remote... Displaying 20 matches (use --all to see all).
20.6.1
20.6.0
20.5.1
20.5.0
20.4.0
20.3.1
20.3.0
20.2.0
20.1.0

## 20.1.0を利用
$ sudo n 20.1.0
Enter fullscreen mode Exit fullscreen mode

テンポラリの node と npm を削除

$ sudo apt purge -y nodejs npm
$ sudo apt autoremove -y
Enter fullscreen mode Exit fullscreen mode

yarn インストール

$ npm install -g yarn
Enter fullscreen mode Exit fullscreen mode

結果

基本は安定板を利用。

$ node -v
v18.17.1
$ npm -v
9.6.7
$ yarn -v
1.22.19
Enter fullscreen mode Exit fullscreen mode

以上

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay