Manage Multiple Versions of Node JS using NVM
Tags: node, javascript, beginners, webdev
Published: 2022-02-19 22:32:26

If you're a node JS developer who has been working in the industry for a long time, you should have to work with different projects that use different versions of node JS. Every time you are working on such a project, are you going to uninstall and re-install the relevant version of node JS? or are you going to create separate environments for each project. 

But there is an easier way now. 

**NVM to the rescue**

Using `nvm`, you can install multiple node JS versions on your computer without extra effort. 
NVM was created to use on Linux systems, but there is an alternative solution for Windows OS.

-------------------------------------
## Linux Setup

Installing nvm on Linux is very easy. You just need to follow the installation steps mentioned in the docs

Run the following command in your Linux terminal

`curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash`

This script will automatically export and set the necessary path variables.

After the script runs successfully, open a new terminal session and type `nvm` . You should be able to see the nvm help page

![nvm help page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xz8svztlwcdd8opkcv60.png)
 
-----------------------------
## Windows Setup

To configure nvm on windows, we can use [nvm-windows](https://github.com/coreybutler/nvm-windows) library. This is pretty much similar to [nvm](https://github.com/nvm-sh/nvm) but not the exact copy of it.

Download the latest version of nvm-windows from the [releases page](https://github.com/coreybutler/nvm-windows/releases)

After downloading install the nvm by using nvm-setup.exe

If you get a confirmation message like this, **accept** it. It will allow the already installed versions of node js to be managed by nvm.

![version confirmation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwsm231c9ejvcqlfr8j0.png)

Once it is successfully installed, open a new terminal session and type `nvm`. you should be able to see the nvm help page.
 

![nvm help page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ez5wa9p3evn48zi0afai.png)
---------------------------
### !!! IMPORTANT !!!

It is important to close any already running terminal sessions and open a new terminal to check the installation.

> Remember when running nvm install or nvm use, Windows usually requires administrative rights (to create symlinks).

-------------------
## Basic Commands

Now lets see some basic commands that will be helpful in version management.

### `nvm current`
This command will show the active node JS version.

### `nvm install`
This can be used to install specific version of node JS in your computer.

**Windows OS will require administrative rights to perform this action.**

**Examples**

`nvm install 17.5.0`
this will install version 17.5.0 of node JS in your computer.

`nvm install lts`
This will install LTS version of node JS. 

### `nvm list`
This will show the currently installed versions of node JS.

![Installed versions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n63qif6tepb8z6nfls9j.png)

Run `nvm list available` to list all available node JS versions to install.
 
 ![all available node JS versions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtolw97hwybonc9xh2ho.png)

### `nvm use xx.xx.xx` 
This will tell the nvm to use specific version of node JS.

**Windows OS will require administrative rights to perform this action.**

**Example**

`nvm use 16.14.0`
This will use specific version of 16.14.0.

![nvm use specific version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/re44i1qhyavscrhp9wcr.png)

Lot more commands are available in the docs.

- [Windows](https://github.com/coreybutler/nvm-windows)
- [Linux](https://github.com/nvm-sh/nvm)
 
---------------------------

Another good tool to manage JavaScript toolchains is [volta](https://volta.sh/). Let's see this in my next tutorial