Using Multiple Node.js Versions with NVM

·

3 min read

nvm stands for Node Version Manager and allows developers to easily manage and switch between different Node versions in the same development machine. It provides a set of commands that you can use to install any version with a single command, set a default, switch between them, etc.

You can install a specific version of Node.js using the nvm install command followed by the version number. Let's see this by example:

nvm install v14.15.5

By running this command, nvm will install Node.js version 14.15.5.

nvm follows SemVer, so if you want to install, for example, the latest 14.15 patch, you can do it by running:

nvm install 14.15

In this case, nvm will install Node.js version 14.15.V, where V is the highest available version.

You can get the full list of available versions by running the following command:

nvm ls-remote

Now that we have seen how we can install specific Node versions, let’s see how to switch between them.

When a version of Node is first installed, it’s automatically activated. So if you run node -v right after, you’ll see the version of the installed Node.

If you need to switch between the installed versions, you can use the nvm use command followed by a version number or an alias.

For example, we can switch to Node.js version 15.1.0 using:

nvm use 15.1.0

We can also switch to the latest Node.js version using the node alias:

nvm use node

Switch to the latest LTS version:

nvm use --lts

After switching to a specific version, nvm will make the node instance in your terminal symlink to the right Node.js instance.