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 Zorin OS 18.1 Pro (Ubuntu 24.04 Noble base) Hardware Lenovo ThinkPad L14 Gen 2

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 usually install it through the package manager. Ubuntu 24.04 ships with a recent Node.js version in its repositories, so a simple apt install is a practical starting point if you just need one system-wide version.


Solution

Option A: From Ubuntu Repository (Simplest)

sudo apt update
sudo apt install nodejs npm

Verify:

node --version
npm --version

At the time this guide was tested on Ubuntu 24.04, this installed Node.js v22.x and npm 10.x. Check node --version and npm --version on your own system, because repository versions can change over time.

Option B: Using nvm (Node Version Manager)

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

# Install nvm
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 A (apt)
Working on multiple projects with different Node versionsOption B (nvm)
Following a tutorial that specifies a Node versionOption B (nvm)

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