How to Manage Multiple Node Versions in MacOS. (2021 Guide)


In this tutorial, you will install nvm and learn to install, remove, and switch between different versions of Node.js.


Step 1 — Getting Started

curl -o- | bash

If you prefer wget, you can run this command:

wget -qO- | bash

Then you will see an output similar to below:

Running either of the above commands downloads a script and runs it. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc). If you don’t see in our profile file you can add the following lines to end of the file as follows.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
My ~/.zshrc file

With nvm installed, then restart your terminal and see if you can check the nvm version as follows.

nvm --version
nvm — version

If you are facing any issues you can check the troubleshooting guide in order to fix any common errors. The next step is to install and work with multiple versions of Node.js.

Step 2 — Installing Multiple Node.js Versions

nvm install node # "node" is an alias for the latest version

To install a specific version of node:

nvm install 6.14.4 # or 10.10.0, 8.9.1, etc

Installing LTS version of a given version:

If you want to install an LTS version of a given release, you can just mention the version number as follows to install particular LTS versions of that release.

nvm install 12

Then, You will see an output as follows:

installing node 12 LTS

The first version installed becomes the default. New shells will start with the default version of node (e.g., nvm alias default).

Changing the default version of node:

During the time of the release of this tutorial, the latest stable version of Node.js is version 15.12.0.

To set the latest stable version as your default, run:

nvm alias default stable

You may also have a specific version number you would like to set as your default. To alias default to a specific version, run:

nvm alias default 12
changing default version

Step 3 — Listing Installed Node.js Versions

nvm ls

The output produced by running this command might look something like this:

nvm ls

Your output will probably differ depending on how many versions of Node.js you have installed on your machine.

The little -> indicates the active version and default -> indicates the default version of Node.js. The default version of Node is the version that will be available when you open a new shell. system corresponds with the version of Node.js installed outside of nvm on your system.

Step 4— Switching Between Node.js Versions

nvm use 8

This is the output you will see:

nvm use 8

You can even switch back to your default version:

nvm use default

At this point, you have installed several versions of Node.js. You can use nvm to uninstall any unwanted version of Node.js you may have.

Step 6 — Removing Node.js Versions

Fortunately, you can remove Node.js versions just as easily as you installed them:

nvm uninstall 8

Unfortunately, when you specify a major or minor version, nvm will only uninstall the latest installed version that matches the version number.

So, if you have two different versions of Node.js version 6 installed, you have to run the uninstall command for each version:

$ nvm uninstall 6
Uninstalled node v6.14.4
$ nvm uninstall 6
Uninstalled node v6.10.3

It’s worth noting that you can’t remove a version of Node.js that is currently in use and active.

You may want to return to your system’s default settings and stop using nvm. The next step will explain how to do this.

Step 7 — Un installing Node Version Manager(NVM)

nvm unload


$ echo "12" > .nvmrc

Hope I have covered everything you need to know in order to manage multiple version of node in your Mac OS. Also, you can look at the following articles on how you can install and use multiple versions of Java and Python in Mac OS.

How to Manage Multiple Java Versions in MacOS

How to Manage Multiple Python Versions in MacOS

Versatile Full-stack Developer with 5+ years of experience designing, developing, and managing complex applications and internal frameworks.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store