Node.js and npm via nvm

Install and manage multiple Node.js versions using nvm — the correct approach for avoiding permission issues on Linux.

Beginner Verified Working Updated 3 min read Tested on Linux Mint 22.3 Cinnamon (Ubuntu 24.04 Noble base); also tested on Zorin OS 18.1 Pro Hardware Lenovo ThinkPad L14 Gen 2 (Intel i5-1135G7, 16GB RAM, Intel Iris Xe, 1366x768)

What This Guide Achieves

GoalStatus
Install Node.js and npmDone

Prerequisites


The Problem (Windows User Perspective)

On Windows, you download the Node.js installer from nodejs.org and run it. On Linux, you might reach for apt install nodejs, but Ubuntu 24.04’s default repositories ship Node.js v18.x — several major versions behind the current LTS. If your project requires Node.js >= 22 (as this documentation site does), the apt version is too old. The solution: use nvm (Node Version Manager) instead.


Solution

Warning: Ubuntu 24.04 Noble ships Node.js v18.19.x in its default repositories — several major versions behind the current LTS. If your project requires >= 22, skip Option A and use nvm (Option B).

sudo apt update
sudo apt install nodejs npm

Verify:

node --version   # Expect v18.x on Ubuntu 24.04, not v22
npm --version

At the time this guide was written (April 2026), apt install nodejs on Ubuntu 24.04 Noble installs Node.js v18.19.1. Only use this if your project targets v18.x specifically.

Removing the apt-installed version (before switching to nvm)

If you already installed Node.js via apt and want to switch to nvm, remove the old version first to avoid PATH conflicts:

# Remove Node.js and its runtime library
sudo apt remove nodejs -y

# Clean up auto-installed dependency packages
sudo apt autoremove --purge -y

# Verify the system Node.js is gone
which node
# Should return nothing or "node not found"

Option B: Using nvm (Node Version Manager)

If you need multiple Node.js versions or want the absolute latest:

# Install nvm — check https://github.com/nvm-sh/nvm/releases for the latest version tag first
# Replace v0.40.1 below with whatever the current release shows
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# Reload your shell
source ~/.bashrc

# Install the latest LTS version
nvm install --lts

# Verify
node --version
npm --version

With nvm, you can switch between Node versions:

nvm install 20    # Install Node 20
nvm install 22    # Install Node 22
nvm use 20        # Switch to Node 20
nvm use 22        # Switch back to Node 22
nvm ls            # List installed versions

Which Option to Choose?

ScenarioUse
Just need Node.js for one projectOption B (nvm) — apt version is too old for most modern projects
Working on multiple projects with different Node versionsOption B (nvm)
Following a tutorial that specifies a Node versionOption B (nvm)
Only targeting Node.js v18.x specificallyOption A (apt)

Troubleshooting

SymptomCauseFix
npm has broken dependencies via aptConflict between system npm and Node.js npmUse nvm instead, or sudo apt install nodejs without npm (npm comes with Node)
nvm: command not found after installShell not reloadedRun source ~/.bashrc

Complete Removal

If installed via apt:

sudo apt remove nodejs npm

If installed via nvm:

nvm deactivate
rm -rf ~/.nvm
# Remove nvm lines from ~/.bashrc

Discussion