How to manage multiple Node.js versions with Node version manager (NVM)

Vahid Akhtar
3 min readSep 15, 2024

--

nvm

Managing different versions of Node.js is crucial for developers working on multiple projects, each requiring specific Node.js environments. This article provides a comprehensive guide to using Node Version Manager (NVM), a tool designed to make switching between Node.js versions seamless and efficient. Readers will learn how to install NVM, the benefits it offers, and step-by-step instructions for managing multiple versions of Node.js. The article covers commands to install, switch, and uninstall Node.js versions, helping developers streamline their workflow, ensure compatibility, and avoid version-related conflicts across projects. Whether you’re maintaining legacy code or developing new features, NVM is an essential tool for Node.js developers.

Installation

Depending on your OS, you will find two different tools. They’re both called nvm, but they're not exactly the same, nor were they meant to be. One is for Windows; the other one is for Mac and Linux.

In both cases, you will find much more documentation already in the README, so I won’t go too much into detail here. The quickest way for windows is to use the installer, while for Linux/MacOS you can use the curl command (copy-paste it into your terminal).

Usage

Once installed, you can use the nvm command in your terminal. The first thing you need to do is to install the Node.js version you want to use. You can find the list of available versions here: https://nodejs.org/dist/index.json

For example, if you want to install Node.js 16, you can run:

nvm install 16

This will install Node.js 16 and make it the default version. You can check the current version with below command

node -v

You can also install 18 versions, for example:

nvm install 18

At this point, you’ll end up having two different versions of Node.js installed on your machine.

nvm list
// 16 and 18

and you can switch between them using the use command:

nvm use 18

You can also specify minor and patch versions, for example:

nvm install 18.14.0
nvm use 18.14.0

If you install a version by mistake or you simply want to remove one for some reason, you can use the uninstall command:

nvm uninstall 18.14.0

Note: changes are local to the terminal where you’re running the command. If you open a terminal in a different folder, you’ll find yourself in the default version again. This is actually quite handy if you need to run multiple projects with different versions at the same time (let’s say backend and frontend of your project).

Multiple projects

NVM (Node Version Manager) is an essential tool for developers working on multiple projects that require different versions of Node.js. It allows you to easily install, switch, and manage multiple Node.js versions on a single machine. Whether you’re maintaining legacy applications or working on the latest projects, NVM ensures compatibility by allowing you to run the required Node.js version for each project. This flexibility streamlines development, preventing conflicts and eliminating the need for global installations. With simple commands, you can switch between versions, making NVM a must-have for any Node.js developer managing diverse projects.

Thanks for reading this article; I hope you found it interesting!

For more context, refer to: https://github.com/nvm-sh/nvm

Links and Resources

--

--

Vahid Akhtar
Vahid Akhtar

No responses yet