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 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?
| Scenario | Use |
|---|---|
| Just need Node.js for one project | Option A (apt) |
| Working on multiple projects with different Node versions | Option B (nvm) |
| Following a tutorial that specifies a Node version | Option B (nvm) |
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