paint-brush
Node Version Manager (NVM): How to Install and Use (Step-by-Step Guide)by@sanzhanov
6,618 reads
6,618 reads

Node Version Manager (NVM): How to Install and Use (Step-by-Step Guide)

by Alex SanzhanovNovember 17th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

As it turns out, the correct installation and usage of NVM on Windows OS often raises some questions due to the fact that there are some inaccuracies in the official repository of this tool. In this regard, in this article, I will tell you how to install NVM on your computer step by step in a more optimal way (MacOS users do not need to read this).

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Node Version Manager (NVM): How to Install and Use (Step-by-Step Guide)
Alex Sanzhanov HackerNoon profile picture


As it turns out, the correct installation and usage of NVM on Windows OS often raises some questions due to the fact that there are some inaccuracies in the official repository of this tool. In this regard, in this article, I will tell you how to install NVM on your computer step by step in a more optimal way (MacOS users do not need to read this).

NVM: What's the point? 🤨

Node Version Manager (NVM) is a tool that allows you to have multiple versions of Node.js on your device, switch them quickly, and it is managed from the command line interface (CLI).

Why is this needed? The fact is that different applications you work with can be implemented on different versions of Node.js. In practice, this is usually indicated by the .nvmrc file which is committed with your project and contains a single line with the version of Node.js to use for this project. However, running the application in another environment may not give the expected result or lead to errors.


Can I do without it? The cases when NVM is just an indispensable thing occur very often in the workplace. Let me give you a small example from my past experience. Having come to work for a new company some time ago, I had to quickly get to the bottom of one of their past projects. At that time, we seemed to be using Node.js version 14.16.0, but the project repository required version 10.x. Of course, if I did not know about NVM, I would only have to reinstall from one version to another. And so for each new project! Definitely, it would be a big headache and a waste of working time.

Moreover, when you work on a large team, it's rare that everyone is using the same version of Node.js.

How to install NVM correctly? 🤔

Well, let's get started with NVM installation. Along the way, I will point out the inaccuracies in the official repository that I mentioned at the very beginning of this article. Here I'm only emphasizing that the further explanation is based on the example of the 11th version of Windows OS.


  1. To begin, open the terminal application on your computer. For Windows, I recommend using Git Bash due to some commands may not be available in Windows PowerShell. Ideally, use the built-in Windows Terminal, in which you need to add Git Bash.


    Let's make sure NVM is not already installed on your computer. Just enter the command:

    nvm -v
    


    If this is correct, then you will see the following response:

  2. Go to the NVM for Windows releases page and select the latest version (the top one in the list), for example, it is currently 1.1.10. Then download the nvm-setup.exe file:

  3. I assume that most of you already have Node.js installed at this point (if not yet, then NVM will do it for you a little later). And if we turn to the official manual, it states that before installing NVM we need to uninstall any existing versions of Node.js:

    However, we will not follow this advice. Instead, run the downloaded setup file. You'll be prompted to agree with the project's terms of use (сhoose 'I accept the agreement' option), then the installer will ask where to install NVM (click on the 'Next' button).

    And now attention!

    You'll be prompted to indicate where to set the Node.js Symlink. This is the next inaccuracy of the official manual because the default path C:\Program Files\nodejs is not correct:

    I strongly recommend changing this path to any other, that does not contain spaces. For example, I specified the following folder in the user's home directory:

    In the next window, click the 'Install' button. Immediately after installation, NVM recognizes that you already have Node.js installed and asks the following question:

    Select the 'Yes' option and the installation process will complete.


  4. Now restart the terminal application and make sure NVM is installed:

    nvm -v
    


    If everything was successful in the previous step, you will receive the following response:

Usage 😃

  1. First, make sure NVM is enabled:

    nvm on
    


    Expected response:

  2. Check the active version of Node.js:

    nvm current
    


    Expected response (in your case it may be another version):

  3. Download the latest version of Node.js:

    nvm install latest
    


    Expected response (in your case it may be another version):

    Also, I can download a specific version of Node.js, for example, 14.18.0:

    nvm install 14.18.0
    


    Expected response:

    If you want to remove a specific version use the command:

    nvm uninstall <version>
    


  4. Open a list of all versions installed on your computer:

    nvm list
    


    Expected response:

  5. Switch to use the specified version:

    nvm use 14.18.0
    


Expected response:

A complete list of commands can also be seen in the official repository.


Well, that's where I end. I really hope that this article will help you properly install and use this wonderful and very useful tool. If you have any questions, write them in the comments below. 👋