Easy Way to Install Multiple Version of Node JS

Bagus Budi Cahyono
Remote Worker Indonesia
5 min readJul 3, 2021
Photo by Clément Hélardot on Unsplash

Basically, installing Node JS on your machine is very easy. If you are using mac or windows, you can just download the package from the official website, then install it. Alternatively, you can install it via Homebrew for mac. If you are using Linux, just install it via the package manager of your Linux distro, for example, use pacman for Arch Linux, and use apt-get for Debian-based. When your installation process is successful, you will have one version of Node js.

In some cases, you need multiple versions of Node JS on your computer. Especially if you work with multiple projects that require a different version of Node JS. Another reason that might make you want to install multiple versions is that you might want to use the LTS version for your current project but you also want to try new features of the latest version of Node JS. The best solution is to install two or more versions of Node JS on your computer. In case you are under the same circumstances, this post is right for you.

In this post, I will show you how to install multiple Node JS on your computer with the help of NVS (Node Version Switcher). NVS is a cross-platform utility for switching between different versions of Node JS. You can easily install and switch to a different version of Node JS anytime you want.

NVS Installation process only takes less than a minute. Below are the steps to install it.

Install NVS on Windows

There are two ways to install NVS on your windows computer. You don’t need to do both, you can choose one of them.

  1. Download the NVS msi file here (windows installer), then install it the same way as you install other windows applications.
  2. Use chocolatey (choco). Make sure you already have choco installed. Go to the chocolatey official website if you do not install it yet. When you have choco, you can install NVS by running this command
choco install nvs

Install NVS on Mac and Linux

You only need to run this command to install NVS on your mac / Linux.

export NVS_HOME="$HOME/.nvs"
git clone <https://github.com/jasongin/nvs> "$NVS_HOME"
. "$NVS_HOME/nvs.sh" install

The above command will add variable NVS_HOME which has value path $HOME/.nvs. For example, If my home directory is /Users/baggus, then NVS_HOME is /Users/baggus/.nvs This location will be used by nvs to put nvs code and your Node JS installation.

The second line of the command is to clone the nvs repository and put it inside NVS_HOME directory. The last command, it will run nvs.sh, which will add nvs shell function to the environment. The install command will add lines on your ~/.bashrc, ~/.profile, or ~/.zshrc file to source nvs.sh (depending on what shell you use). With this command, the nvs command will be available in your shells.

After you have successfully installed nvs, you can verify the installation by run command on your shell/terminal

nvs --version

Managing Multiple Versions of Node JS via NVS

Now you have nvs installed on your computer. Let’s start installing NodeJS. In this example, I will show you how to install two versions of Node JS, and how to switch versions between them.

Actually, you have two options, you can use an interactive menu of NVS, or you can type your command as you want. For accessing the interactive menu, you run the command nvs without any parameter.

nvs

When the command executed, you will see the interactive menu like this.

Then you can choose a specific version of Node JS that you want to use. After you choose a version, NVS will download and install Node JS for you. Next time you run nvs command, you will see like this.

I choose to install Node vesion 14.17.2. It will show up on interactive menu

I think this is really easy so that you can do it on your own.

Next, I will show you how to do it via nvs command. In this example, I want to install the LTS version and the latest version. When I write this post, the LTS version is 14.17.2 and the latest version is 16.4.1

Follow these steps

  1. Install v14.17.2 (LTS)
nvs add 14.17.2

or you can also simply run

nvs add lts

2. Check the list of Node JS version installed

nvm ls

You will see that version 14 there. It means that your installation of version 14 is successful. Your Node JS 14 is installed on ~/.nvs/node/14.17.2/

3. Start to use version 14

nvs use 14

or

nvs use lts

The command nvs use will switch versions for your current shell only. When you close your shell, the version used is still the default version. If you want to use it permanently (as your default), run nvs link lts

4. Check the Node JS version you use

node -v  // will show output 
// v14.17.2

Next, I will install version 16 (latest), and switch to that version.

5. Install version 16

nvs add 16.4.1

or

nvs add latest

6. Switch to that version

nvs use 16

or

nvs use latest

7. Check Node version

node -v  // will show output 
// v16.4.1

Now you have already familiar with the NVS command. It is really easy to use. I highly recommend you to use NVS or other node version managers before starting to develop a Node JS application.

To see the list of all NVS commands, visit NVS repository https://github.com/jasongin/nvs#command-reference

References:

I am a part of the Indonesian remote worker community (remoteworker.id). We upgrade skills, learn together, and share knowledge with each other. We work from anywhere, but we are united. Let’s unite as Indonesian. Together, we can achieve more. If you want to be one of the Indonesian remote workers, join our community here.

--

--