Introduction To Node Version Manager

Sarthak Pranesh
VIT Linux User Group

--

Hello Node developers and enthusiast, ever wondered how will it be to use different versions of Node for your different applications or ever had issues in installing Node on your fresh Linux machines. Well if you had had these issues then here is the easiest way to solve it, that too in style.

What Is NVM?

Node Version Manager or NVM is the answer to all of this. It allows the developers to install multiple versions of Node in their machine and at the same time provide them with a very easy seamless switching experience between different versions of Node.

In this article we will go from installing NVM to utilizing it to its full potential, so why wait lets dig in!

Let’s Install NVM!

First we’ll need to make sure we have what it takes to install NVM, right?

Let’s install the required C++ compilers to make sure that the installation of NVM goes smooth. So make sure you follow the instructions below carefully for your respective machines.

  • Mac users run the following command in a terminal, make sure you hit “Install” when the popup appears.
  • Ubuntu or Debian users will have to run the following two commands in there terminal, make sure to type in your password correctly.

After you have installed the required tools, it’s time we install NVM.

Run the command below in a terminal ( Same command for both Ubuntu and Mac users )

Final step, let’s verify if our installation was successful

Close the existing terminals and open a new one, and then run the following command.

If the command worked you’ll see something like the following

The command is used to check what version of the nvm is installed

Now its time to NVM 🥳….

Installing Node

Let’s start with listing all the available Node versions, right from the version v0.1.14. To do so run the following NVM command and it will list out all the Node versions with the LTS releases marked.

The result of this command will look similar to the following, you might get more recent releases depending on when you are reading this article.

The latest version being v13.2.0 and the LTS being v12.13.1

Now lets say we wanna try the latest release of Node, hence v13.2.0 ( Your Latest Release maybe different, feel free to try that one ). For doing so run the following command.

You can choose to install another version of Node if you wish too. After running the above command we would get something like the following.

NVM first downloads the specified version of Node and then sets it up automatically for us. So now lets see what Node version we are using by running the following command.

This command will output the Node version you just installed, verifying the install

What About Multiple Node Versions?

The same command ( nvm install version ), can be used to install any different version of Node alongside any existing installed versions.

For example lets install the latest LTS version of Node, which was v12.13.1 ( we got this info from running “nvm ls-remote” remember? ). So for installing Node v12.13.1 we run the following command.

This installs the Node version 12.13.1 on our machine and sets it up for use

On running the above command we get the following results, which is similar to what we got earlier.

This confirms the installation of Node v12.13.1

And now we are using the LTS version of node ( v12.13.1 ).

But What If I Want To Switch Back To The Version I Installed Earlier?

No worries NVM got your back. All we need to do is list out the versions of Node installed on our machines and then tell NVM to use one of those installed versions.

For doing so first we list out installed versions of Node by running the following command.

On running the above command we get a list of all installed node versions that are available on our machine. The result looks like the following

We can clearly see how I have other versions of Node installed too

Now for selecting one of the version of Node from the list of all versions installed on our machine, we need to tell NVM which version to use, and we do so literally by using the following command

On running the above command we shall get an output like below

To verify if the Node version currently used by our machine is switched or not, we run the following command

On running the above command we see that our Node version is no more v12.13.1 ( or whichever LTS version you installed ) but its switched to version v13.2.0 ( or whichever latest version you installed )

Conclusion

NVM or Node Version Manager is a great tool for developers wanting to develop applications that involve the use of different Node versions. The ease and seamless way of installing, managing and switching between different Node versions is just remarkable. It can really help save a lot of time. A special thanks to all the NVM developers, you guys helped me save a lot of time.

NVM YOUR LIFE NODE DEVELOPERS

--

--

Sarthak Pranesh
VIT Linux User Group

Full Stack | React Native | Gopher | Open Source and Linux Enthusiast | Indian | Hindu