How to Install NVM on Ubuntu

Install NVM on Ubuntu with the official install.sh script, load it in bash or zsh, install LTS Node.js with nvm install --lts, switch versions with nvm use, set a default alias, and fix nvm command not found and Snap curl download failures.

Published

Updated

Read time 7 min read

Reviewed byDeepak Prasad

Install NVM on Ubuntu banner with nvm install command and Node.js version output

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).

IMPORTANT
NVM is not an apt package—Ask Ubuntu documents installing it from the upstream GitHub installer. Install it as your normal user, not with 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 (no sudo for the NVM script itself).
  • cURL or wget plus git—the installer clones the nvm repository.
  • Outbound HTTPS to raw.githubusercontent.com and nodejs.org (corporate proxies may need https_proxy).

Refresh apt and install the tools:

bash
sudo apt update
sudo apt install -y curl git ca-certificates

On 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:

bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash

Equivalent with wget:

bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash

On a clean test account, the tail of the install looked like this:

text
=> 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_completion

The 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).

WARNING
If the script prints 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:

bash
source ~/.bashrc

For zsh (Ubuntu 24.04+ often defaults to zsh in some setups):

bash
source ~/.zshrc

If you use another POSIX shell, see the nvm Linux troubleshooting notesksh 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.

bash
command -v nvm
nvm --version

Example:

text
nvm
0.40.5

nvm --help lists subcommands (install, use, ls, alias, uninstall, and others).


Step 4: Install Node.js with NVM

Install the latest LTS release

bash
nvm install --lts

On Ubuntu 25.04 this pulled Node v24.18.0 (npm v11.16.0):

text
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:

bash
node -v
npm -v
text
v24.18.0
11.16.0

Install a specific major version

bash
nvm install 22
nvm use 22
node -v
text
Downloading and installing node v22.23.1...
Checksums matched!
Now using node v22.23.1 (npm v10.9.8)
v22.23.1

List installed and remote versions

bash
nvm ls
nvm ls-remote --lts | tail -6

Installed list (arrow -> marks the active version):

text
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):

text
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.

NOTE
Compiling Node from source (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:

bash
nvm use --lts
nvm uninstall 22
text
Uninstalled node v22.23.1

If you see Cannot uninstall currently-active node version, run nvm use <other> or nvm deactivate first.


Remove NVM completely

  1. Unload NVM from the current shell:
bash
nvm unload
  1. Delete the install directory:
bash
rm -rf "${NVM_DIR:-$HOME/.nvm}"
  1. Edit ~/.bashrc (and ~/.zshrc if applicable) and remove the block the installer added:
bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
  1. Open a new shell and confirm command -v nvm prints 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


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.


Frequently Asked Questions

1. How do I install NVM on Ubuntu?

NVM is not in Ubuntu apt. Run curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash (or the wget equivalent), then source ~/.bashrc or open a new terminal. Verify with command -v nvm and nvm --version.

2. Is NVM available in the Ubuntu repositories?

No. Ask Ubuntu and Debian package indexes do not ship nvm—you install it per user from the nvm-sh GitHub project. Ubuntu apt provides nodejs and npm as system packages, but those are a single distro version, not a version manager.

3. Why is nvm command not found after installation?

The installer appends source lines to ~/.bashrc, ~/.zshrc, or ~/.profile. Run source ~/.bashrc (bash) or source ~/.zshrc (zsh), or open a new terminal. Use command -v nvm—not which nvm, because nvm is a shell function, not a binary in PATH.

4. How do I install the latest LTS Node.js with NVM?

After loading nvm, run nvm install --lts. That downloads the current LTS tarball from nodejs.org, verifies the checksum, and switches your shell to it. Set nvm alias default lts/* so new shells start on LTS.

5. How do I switch between Node versions with NVM?

Install versions with nvm install 22 or nvm install 24, list them with nvm ls, and activate one with nvm use 22. In a project directory, echo lts/* > .nvmrc then nvm use reads that file automatically.

6. What is the difference between NVM and sudo apt install nodejs?

apt nodejs is one system-wide version managed by Ubuntu security updates. NVM installs multiple Node versions under ~/.nvm/versions/node for your user account and lets you switch per shell or per project—better when different apps need Node 20 vs 22.

7. NVM install fails to download nvm.sh when I use curl—what now?

On Ubuntu, a Snap-packaged curl can break the pipe-to-bash installer (GitHub issue nvm-sh/nvm#2504). Remove it with sudo snap remove curl, install apt curl via sudo apt install curl, then rerun the install script.

8. How do I uninstall NVM from Ubuntu?

Run nvm unload, remove ~/.nvm with rm -rf, and delete the NVM_DIR source block from ~/.bashrc (or ~/.zshrc). Uninstall individual Node versions first with nvm uninstall when they are not active.

9. Should I run the NVM install script as root?

No. NVM is designed for your normal user and installs into $HOME/.nvm. Running the script with sudo puts files under /root and breaks the expected workflow—use your developer account instead.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …