Skip to content

How To Run Multiple Versions of Node and NPM with Node Version Manager

You’ve encountered this at some point if you work on many Node.js projects. You have installed the most recent Node.js version, but the project you’re about to work on requires an older version.

In such cases, the Node Version Manager (nvm) is an excellent tool that comes in handy, allowing you to install different versions of Node.js and switch between them as needed.

Today, we will tell you all you need to know to run multiple versions of Node and NPM with Node Version Manager!

Let’s dig in!

But first, What are NPM and NVM?

You’ve probably heard developers talk about NPM, Node.js packages, or Packager Manager if your firm uses Node.js. But what is it?

NPM/Node Package Manager – is the built-in package manager for JavaScript’s runtime Node.js.

It’s also known as “Ninja Pumpkin Mutants & Nonprofit Pizza Makers” and a slew of other names you can look into and possibly contribute to over at npm-expansions.

NPM is broken down into two parts:

  • a command-line interface (CLI) application for publishing and installing packages
  • an online repository for JavaScript packages
What about NVM?

nvm or Node Version Manager lets you quickly install and utilize multiple Node versions via the command line. nvm was designed for Linux systems, although it can also be installed on Mac.

Instead of implementing npm to install and uninstall Node versions for your various projects, you can simply use nvm, which allows you to manage your Node versions for each project more effectively.

NVM enables you to install different Node versions and switch between them via the command line, depending on the project you’re working on.

Now that we have cleared the basics, let’s move on to the best part.

How To Install Multiple Versions Of Node.js?

Depending on the project’s needs, we can easily switch between different Node versions with the aid of Node Version Manager or NPM. Here’s how.

Step: 1

The first step is to install Node Version Manager. Here’s how you can install the latest version of NVM

curl -o- | bash
Step: 2

Next, add these lines in the .bash_profile

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Step: 3

Now, we can install the node using the version, establishing the latest version node. To do it, type the command below.

nvm install 16

If you want to uninstall the version, here’s how. Simply type the below command:

nvm uninstall 16

Or, if you want to list the installed node version, here’s your command:

nvm list

Congratulations! You have learned to run multiple versions of Node and NPM with Node Version Manager.

Wrapping up

It doesn’t have to be a nightmare to work on many projects that use different versions of Node.js because the task is made easier by Node Version Manager.

If you want to prevent remembering to switch versions, you can create a .nvmrc file, or nvmw or nodist files in the root of your project as alternatives!

Need help with web development with NodeJS? We can help! Reach out to the best web development company in Coimbatore! Get a free quote today!

Bhavanaditya D R

Sr. Front-End Developer