NVM (Node Version Manager) is a POSIX shell script that installs and switches between multiple Node.js and npm versions on the same Ubuntu machine. If one project needs Node 20 LTS and another tracks Node 22, NVM keeps each version under ~/.nvm and changes what node and npm resolve to in your shell—without replacing the system nodejs package Ubuntu may already ship.
This guide shows how to install NVM on Ubuntu using the official nvm-sh/nvm install.sh script, load it in bash or zsh, install LTS Node, switch versions, use a .nvmrc file, and remove NVM when you no longer need it. I ran every command on Ubuntu 25.04 and kept trimmed terminal output below so you can compare your host.
Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic; nvm v0.40.5; Node v24.18.0 LTS (Krypton).
sudo, so files land in ~/.nvm.
Quick command summary
| Task | Command |
|---|---|
| Install prerequisites | sudo apt update && sudo apt install -y curl git |
| Install NVM (curl) | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash |
| Load NVM in current shell | source ~/.bashrc (bash) or source ~/.zshrc (zsh) |
| Verify | command -v nvm and nvm --version |
| Install latest LTS Node | nvm install --lts |
| List installed versions | nvm ls |
| Switch version | nvm use 22 |
| Set default for new shells | nvm alias default 22 |
| List remote versions | nvm ls-remote --lts |
| Remove NVM | nvm unload then rm -rf ~/.nvm and edit shell rc file |
Pin v0.40.5 in the URL to match the latest nvm release when you install—update the tag if a newer version shipped after this article was written.
Prerequisites
- Ubuntu 22.04 LTS, 24.04 LTS, or newer (25.04 tested here) on amd64 or arm64.
- A normal user account with write access to
$HOME(nosudofor the NVM script itself). - cURL or wget plus git—the installer clones the nvm repository.
- Outbound HTTPS to
raw.githubusercontent.comandnodejs.org(corporate proxies may needhttps_proxy).
Refresh apt and install the tools:
sudo apt update
sudo apt install -y curl git ca-certificatesOn Ubuntu 25.04, curl and git were already present; apt install reported they were up to date.
NVM vs apt Node.js vs Snap
| Approach | Best for | Trade-off |
|---|---|---|
| NVM (this guide) | Developers juggling multiple Node versions per project | Per-user install under ~/.nvm; not managed by unattended-upgrades |
sudo apt install nodejs |
Single system Node aligned with Ubuntu security updates | One version; may lag upstream feature releases |
| Node Snap | Quick single-version trials | Different layout and confinement; NVM is the usual choice when you need several versions |
For a manual tarball install without NVM, see install Node.js from tar.xz on Ubuntu.
Step 1: Run the official NVM install script
The nvm-sh install documentation recommends piping install.sh into bash. cURL is the usual choice on Ubuntu:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bashEquivalent with wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bashOn a clean test account, the tail of the install looked like this:
=> Downloading nvm from git to '/home/user/.nvm'
=> Cloning into '/home/user/.nvm'...
* (HEAD detached at FETCH_HEAD)
master
=> Compressing and cleaning up git repository
=> Appending nvm source string to /home/user/.bashrc
=> Appending bash_completion source string to /home/user/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completionThe script clones ~/.nvm, checks out the release tag, and appends NVM_DIR lines to your shell rc file (~/.bashrc on default Ubuntu bash, ~/.zshrc if you use zsh).
Failed to download for nvm.sh but a manual wget of the same URL works, check whether curl came from Snap. Stack Overflow and nvm issue #2504 document failures with Snap curl—sudo snap remove curl and sudo apt install curl fixed it on several Ubuntu releases.
Step 2: Load NVM in your current shell
Open a new terminal tab, or source the file the installer modified:
source ~/.bashrcFor zsh (Ubuntu 24.04+ often defaults to zsh in some setups):
source ~/.zshrcIf you use another POSIX shell, see the nvm Linux troubleshooting notes—ksh users typically run . ~/.profile.
Step 3: Verify the NVM installation
Use command -v—not which nvm. NVM is a sourced shell function, so which nvm often prints nothing even when NVM works.
command -v nvm
nvm --versionExample:
nvm
0.40.5nvm --help lists subcommands (install, use, ls, alias, uninstall, and others).
Step 4: Install Node.js with NVM
Install the latest LTS release
nvm install --ltsOn Ubuntu 25.04 this pulled Node v24.18.0 (npm v11.16.0):
Installing latest LTS version.
Downloading and installing node v24.18.0...
Downloading https://nodejs.org/dist/v24.18.0/node-v24.18.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v24.18.0 (npm v11.16.0)
Creating default alias: default -> lts/* (-> v24.18.0 *)Confirm:
node -v
npm -vv24.18.0
11.16.0Install a specific major version
nvm install 22
nvm use 22
node -vDownloading and installing node v22.23.1...
Checksums matched!
Now using node v22.23.1 (npm v10.9.8)
v22.23.1List installed and remote versions
nvm ls
nvm ls-remote --lts | tail -6Installed list (arrow -> marks the active version):
v22.23.1
-> v24.18.0
default -> lts/* (-> v24.18.0 *)
node -> stable (-> v24.18.0 *) (default)
lts/* -> lts/krypton (-> v24.18.0 *)Remote LTS tail (versions change over time):
v24.16.0 (LTS: Krypton)
v24.17.0 (LTS: Krypton)
-> v24.18.0 * (Latest LTS: Krypton)Daily usage: switch versions, default alias, and .nvmrc
| Task | Command |
|---|---|
| Activate a version | nvm use 22 or nvm use --lts |
| Default for new shells | nvm alias default 22 or nvm alias default lts/* |
| Temporarily leave NVM paths | nvm deactivate |
Use system /usr/bin/node |
nvm use system |
| Project pin file | echo "22" > .nvmrc then nvm use |
In a project root, a .nvmrc file with a single version line (22, lts/*, or 20.20.2) lets nvm use and nvm install pick it up when you cd into the tree—handy for teams documented in the nvm .nvmrc section.
After you have Node running, typical next steps include building a small HTTPS server with Node.js or wiring NVM into VS Code on Ubuntu for local web development.
nvm install -s) needs build tools. On Debian/Ubuntu the nvm readme recommends build-essential and libssl-dev when prebuilt binaries are unavailable for your platform.
Uninstall a Node version
You cannot remove the version that is currently active:
nvm use --lts
nvm uninstall 22Uninstalled node v22.23.1If you see Cannot uninstall currently-active node version, run nvm use <other> or nvm deactivate first.
Remove NVM completely
- Unload NVM from the current shell:
nvm unload- Delete the install directory:
rm -rf "${NVM_DIR:-$HOME/.nvm}"- Edit
~/.bashrc(and~/.zshrcif applicable) and remove the block the installer added:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"- Open a new shell and confirm
command -v nvmprints nothing.
Node versions under ~/.nvm/versions/node are removed with step 2—back up projects and global npm packages first.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
nvm: command not found |
Shell rc not sourced | source ~/.bashrc or open a new terminal |
which nvm empty but install succeeded |
nvm is a function |
Use command -v nvm |
Install script cannot download nvm.sh |
Snap curl / sandbox |
sudo snap remove curl; sudo apt install curl |
Failed to clone / git errors |
Missing git or old git | sudo apt install git (nvm needs git ≥ 1.7.10) |
Checksums matched but node wrong arch |
Rare on arm64 with old Node | Pick a Node version with arm64 binaries or nvm install -s with build deps |
npm prefix conflicts |
prefix= in ~/.npmrc |
Remove prefix lines—nvm manages paths per version |
| Want system Node again | NVM still first in PATH | nvm use system or remove NVM |
References
- nvm-sh/nvm — GitHub (official install script and usage)
- Node.js releases (LTS schedule and binaries NVM downloads)
- Install cURL on Ubuntu
- Ask Ubuntu — install nvm
- Stack Overflow — NVM install fails on Ubuntu 20.04
Summary
Installing NVM on Ubuntu means running the upstream install.sh as your user—curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash—then sourcing ~/.bashrc so command -v nvm works. From there, nvm install --lts gives you a current Node LTS build with matching npm, nvm use switches versions for the active shell, and nvm alias default picks what new terminals start with. Watch for Snap-packaged curl breaking the installer, avoid sudo for the NVM script itself, and use .nvmrc when each repo needs its own Node line.

