NVM: Manage Multiple Versions of Node.js on a Single System

Developers often have to depend on multiple versions of the same language, framework, or library. This can happen because one project might depend on the latest version of a language, whereas another project might require a previous release.
Some operating systems and/or languages don’t make the task of using multiple versions of the same language easy. If you happen to use Linux as your development platform and Node.js as one of the many languages you work with, you’re in luck, as there’s a handy tool to make this fairly simple.
The tool in question is called NVM, which stands for Node Version Manager. NVM can be installed on many different Linux distributions, such as Ubuntu, RHEL, CentOS Stream, Rocky Linux, AlmaLinux, and Debian, as well as MacOS and Windows (via Windows Subsystem for Linux).
Essentially, NVM is a version manager for Node.js that is installed on a per-user basis and is invoked from the command line on any POSIX-compliant shell (such as sh, dash, ksh, zsh, and bash).
I’m going to show you how to install and use NVM on Ubuntu Server 22.04.3 and Rocky Linux 9.
What You’ll Need
To use NVM, you’ll need the following:
- Either an instance of Ubuntu or Rocky Linux (or another equivalent, such as AlmaLinux or CentOS Stream).
- Node.js installed.
- A user with sudo privileges.
- A network connection.
That’s it. Let’s get to work.
Installing NVM on Ubuntu Server
Log into your Ubuntu Server instance. If your server includes a desktop environment, open a terminal window.
The next step is to install a few dependencies, which can be done with a single command:
1 |
sudo apt-get install build-essential libssl-dev -y |
Next, download and run the installation script with the command:
1 |
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash |
Once the command completes, log out and log back into your Ubuntu server instance.
Installing NVM on Rocky Linux (or an Equivalent Distribution)
The installation of NVM on Rocky Linux is similar to that of Ubuntu, the only difference being the installation of the dependencies.
To install the dependencies, log into your Rocky Linux instance and, if necessary, open a terminal window. Then, issue the following command to install the dependencies:
1 |
sudo dnf group install "Development Tools" -y |
The installation of the dependencies will take considerably longer on Rocky Linux than it does on Ubuntu. When it completes, you can then issue the same install command on Rocky Linux as you did Ubuntu, which is:
1 |
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash |
When the command completes, log out of Rocky Linux and log back in. You can then verify the installation with the command:
1 |
nvm --version |
The output should be something like this:
1 |
0.39.5 |
NVM is now installed and ready to use.
If you find the prompt returns that NVM isn’t installed, you might have to reload your .bashrc script with the command:
1 |
source ~/.bashrc |
Installing Node.js with NVM
Now that NVM is installed, you can use it to install different versions of Node.js. This process is the same, regardless of which distribution you are using. With NVM, you’ll find it possible to install Node.js versions from v0.1.14 all the way to v20.7.0. Of course, you probably won’t want to go all the way back to beta releases and as Node.js is upgraded, newer releases will be added.
To find the complete list of available Node.js releases for NVM, issue the command:
1 |
nvm list-remote |
The output will look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
v19.0.1 v19.1.0 v19.2.0 v19.3.0 v19.4.0 v19.5.0 v19.6.0 v19.6.1 v19.7.0 v19.8.0 v19.8.1 v19.9.0 v20.0.0 v20.1.0 v20.2.0 v20.3.0 v20.3.1 v20.4.0 v20.5.0 v20.5.1 v20.6.0 v20.6.1 v20.7.0 |
Let’s say your current project requires Node.js version 19.0.1. To install this version, the command would be:
1 |
nvm install v19.0.1 |
When the command completes, you can verify the installation with the command:
1 |
nvm list |
You should see the following output:
-> v19.0.1
system
default -> v19.0.1
If you’ve installed Node.js from your default package manager (such as apt-get), you might see a system entry in the output. If you want to use the version of Node.js installed by the system, you could issue the command:
1 |
nvm use system |
If you have multiple versions of Node.js installed, you can choose which one to use with a command like:
1 |
nvm use v20.7.0 |
The output for the above command will look like this:
1 |
Now using node v20.7.0 (npm v10.1.0) |
With NVM, you can install as many versions of Node.js as needed and switch back and forth between versions with ease. Any time a project demands a different release, switch with the nvm use command and you’re good to go.