Skip to content

Install NVM on Ubuntu

NVM (Node Version Manager) installs and manages multiple Node.js versions per user. The apt nodejs package installs system-wide, is often outdated, and makes version switching difficult. NVM avoids both problems and is the standard for modern JS development.

The install script clones the NVM repo into ~/.nvm and adds initialization lines to ~/.bashrc or ~/.zshrc. Check the nvm-sh/nvm repo for the current release and replace v0.40.4 below if a newer version is out.

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

Either restart the terminal, or reload the shell config in the current session.

Terminal window
source ~/.bashrc

Verify the install.

Terminal window
nvm --version

Install the current LTS, set it as the active version, and pin it as the default for new shells.

Terminal window
nvm install --lts
nvm use --lts
nvm alias default lts/*

Confirm node and npm are available.

Terminal window
node -v
npm -v
Terminal window
nvm install 20 # install a specific major version
nvm use 20 # switch the current shell to that version
nvm alias default 20 # set the default for new shells
nvm ls # list installed versions
nvm uninstall 18 # remove a version

Piping a remote script straight into bash should only be done for trusted sources. To inspect the script before running it, download first.

Terminal window
curl -O https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh
less install.sh
bash install.sh