Node Version Manager (NVM): how to install and use (step-by-step guide)
Tags: nvm, node, testing, beginners
Published: 2022-11-16 19:17:39

*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](https://github.com/coreybutler/nvm-windows) 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? :raised_eyebrow:
>**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? :thinking:
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:
    ```javascript
    nvm -v
    ```
    If this is correct, then you will see the following response:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wiq6yqs6hvvzqbsm5bq.png)

2. Go to the NVM for Windows [releases page](https://github.com/coreybutler/nvm-windows/releases) 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:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qjqitpmbcr4tpuhr3t8.png)

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](https://github.com/coreybutler/nvm-windows), it states that before installing NVM we need to uninstall any existing versions of Node.js:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ccm1iopaituu7cfwgvz.png)

    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:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/keundrric4e9heh8jawu.png)

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

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g61xrqyiqirw1ebds2t9.png)

    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:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnn4pdpb0dhg1gce95oi.png)

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

4. Now restart the terminal application and make sure NVM is installed:
    ```javascript
    nvm -v
    ```
    If everything was successful in the previous step, you will receive the following response:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5li2w96lfdbu06ohj96.png)

##Usage :smiley:

1. First, make sure NVM is *enabled*:
    ```javascript
    nvm on
    ```
    Expected response:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/410y33uhx97kp2jacdd3.png)

2. Check the *active version* of Node.js:
    ```javascript
    nvm current
    ```
    Expected response (in your case it may be another version):

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wea6kyk8w73wiunisu22.png)

3. Download the *latest version* of Node.js:
    ```javascript
    nvm install latest
    ```
    Expected response (in your case it may be another version):

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lmxu1e2r608vsjyr3hyt.png)

    Also, I can download a specific version of Node.js, for example, 14.18.0:
    ```javascript
    nvm install 14.18.0
    ```
    Expected response:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2xaeviwfeqahbca7va6g.png)

    If you want to *remove* a specific version use the command:
    ```javascript
    nvm uninstall <version>
    ```

4. Open a *list of all versions* installed on your computer:
    ```javascript
    nvm list
    ```
    Expected response:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gx1291bz1qfpa7xbf2m9.png)

5. *Switch* to use the specified version:
    ```javascript
    nvm use 14.18.0
    ```
    Expected response:

    ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g4eil5cp65mkpdc3ckuu.png)

A complete list of commands can also be seen in the [official repository](https://github.com/coreybutler/nvm-windows).

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. :wave: