Node.js and npm via nvm
Install and manage multiple Node.js versions using nvm — the correct approach for avoiding permission issues on Linux.
What This Guide Achieves
| Goal | Status |
|---|---|
| Install Node.js and npm | Done |
Prerequisites
- Any Ubuntu 24.04-based distro
- Before mixing system Node.js and
nvm, review the clean installation and removal best practices
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
Option A: From Ubuntu Repository (Not Recommended)
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?
| Scenario | Use |
|---|---|
| Just need Node.js for one project | Option B (nvm) — apt version is too old for most modern projects |
| Working on multiple projects with different Node versions | Option B (nvm) |
| Following a tutorial that specifies a Node version | Option B (nvm) |
| Only targeting Node.js v18.x specifically | Option A (apt) |
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
npm has broken dependencies via apt | Conflict between system npm and Node.js npm | Use nvm instead, or sudo apt install nodejs without npm (npm comes with Node) |
nvm: command not found after install | Shell not reloaded | Run 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
Related Guides
- Package Management Basics — Clean package/source selection and uninstall practices
- VS Code Setup — Development environment configuration
Discussion