How to install nvm on windows

Cover image for How to install Node Version Manager (NVM) for Windows 10?

Introduction

I had recently purchased a Windows 10 laptop and I wanted to install Node.js. I usually prefer to use a Node Version Manager to install Node.js.

The reason I choose to do that is because I usually have to work with multiple applications that need require different Node.js versions, and using a node version manager (NVM) it is very easy to switch versions.

This article is more of a user guide for folks who are interested to install a Node Version Manager for Windows 10 Operating System.

A Quick Look at the Key Terminologies

I wanted to mention the following terminologies for absolute beginners. So, feel free, to skip this section, if you are already familiar.

  • nvm — Node Version Manager. It is a tool that allows you to download and install Node.js. It allows you to pick and choose the Node.js version that you wish to use.

  • Node.js — It is a platform for running JavaScript applications.

  • npm — Node Package Manager. It is a tool that allows you to install JavaScript packages. npm comes along with Node.js. So, if you have installed Node.js, you’ll have npm installed as well.

Installing NVM for Windows 10

Go to the nvm-windows Git Repository

  • Using your browser navigate to the Git repository for nvm-windows located over here.

  • Click on the ‘nvm-setup.zip’ link from the ‘assets’ table as shown in the image below.

1-url.png

Locate the Zip File & Extract

  • The Zip file should have been downloaded to your Downloads folder (or where ever you have configured your downloads to be saved).

2-zip.png

  • Unzip/Extract the contents to the same folder.

3-extract.png

4-extract2.png

  • You should have the file nvm-setup.exe extracted in the same folder.

5-executable.png

Install NVM

  • Double-Click on the executable file to launch the installer.

  • Choose ‘I accept the agreement’ option.

6-accept.png

  • Select destination to install.

7-pathtoinstall.png

  • Select Symlink for Node.js.

8-symlink.png

  • Click on Install & once it completes, click on the ‘Finish’ button.

9-install.png

10-finish.png

Confirm that the ‘NVM’ successfully installed

  • Open your command line terminal

  • Type the below command to verify if your nvm installation was successful.

$ nvm --version

Enter fullscreen mode

Exit fullscreen mode

11-checknvm.png

Install npm

  • You can now install ‘npm’ using the following command.
  $ nvm install latest 
  //installs the latest version of npm

  $ nvm install <<version number>> 
  //e.g. nvm install 12.6.8 to install a specific npm version

Enter fullscreen mode

Exit fullscreen mode

  • Let us install the latest version of npm. (As of Sep 2020)

12-installnpm.png

Specify the version of npm that you choose to use

  • Using the below command to specify the version of npm that you wish to use. In our case, since we have only one version installed. Let’s go with that.
$ nvm use 14.9.0

Enter fullscreen mode

Exit fullscreen mode

13-usenpm.png

Check npm & nodejs versions

  • You can confirm the nodejs and npm versions through the commands below.

//Check Node.js version
$ node --version

//Check npm version
$ npm --version

Enter fullscreen mode

Exit fullscreen mode

14-checknpmnode.png

Install Another npm Version

  • Repeat the above steps

15-installdiffversion.png

  • Install Completed & Select the version using the ‘nvm use’ command

16-finishinstall.png

17-useversion.png

  • Confirm that the environment now points to the new Node.js and npm versions

18-confirmversion.png

List all Versions

  • You can use the nvm list command to list all the npm and Node.js versions installed.
$ nvm list

Enter fullscreen mode

Exit fullscreen mode

19-listversions.png

Conclusion

I hope the detailed user-guide helped you setup the Node Version Manager (nvm) in your Windows 10 machine. Thank you for reading the article and do share it if you found it useful.

Cover Photo by Christina @ wocintechchat.com on Unsplash

You may also like:

  • IIFE — Immediately Invoked Function Expressions
  • ES6 — Spread Operator
  • A Basic Introduction to Webpack
  • ES6 => Arrow Functions
  • ES6 — Understanding Destructuring
  • Why do you want to work for us?
  • Understanding Closures
  • What is ‘this’ in JavaScript
  • Docker Fundamentals

Node Version Manager – NVM Install Guide

In this article, I’ll explain how you can install NVM, or Node Version Manager, on Windows, Linux, and Mac.

What is NVM?

Node Version Manager (NVM), as the name implies, is a tool for managing Node versions on your device.

Different projects on your device may be using different versions of Node. Using only one version (the one installed by npm) for these different projects may not give you accurate execution results.

For example, if you use a Node version of 10.0.0 for a project that uses 12.0.0, you may get some errors. And if you update the Node version to 12.0.0 with npm, and you use it for a project that uses 10.0.0, you may not get the expected experience.

In fact, you would most likely get a warning that says:

This project requires Node version X

Instead of using npm to install and uninstall Node versions for your different projects, you can use nvm, which helps you effectively manage your node versions for each project.

NVM allows you to install different versions of Node, and switch between these versions depending on the project that you’re working on via the command line.

In the next sections, I’ll show you how to install NVM on your Windows, Linux, or Mac device.

Before proceeding, I also recommend that you uninstall Node.js if you have it installed already so that you do not have any conflicts with Node.js and nvm.

How to Install NVM on Windows

NVM is mostly supported on Linux and Mac. It doesn’t have support for Windows. But there’s a similar tool created by coreybutler to provide an nvm experience in Windows called nvm-windows.

nvm-windows provides a management utility for managing Node.js versions in Windows. Here’s how to install it:

1. Click on «Download Now»

In the nvm-windows repository Readme, click on «Download Now!»:

image-338

This will open a page showing different NVM releases.

2. Install the .exe file of the latest release

In the latest release (which as of the time of writing this is 1.1.9), you’ll find different assets. Click on the nvm-setup.exe asset which is the installation file for the tool:

image-340

3. Complete the Installation Wizard

Open the file that you have downloaded, and complete the installation wizard.

When done, you can confirm that nvm has been installed by running:

nvm -v

If nvm was installed correctly, this command will show you the nvm version installed.

How to Install NVM on Linux and Mac

Since Linux and Mac have some similarities (they are both UNIX-based OSes), you can install nvm on them in similar ways.

1. Run the nvm installer

In your terminal, run the nvm installer like this:

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

# or

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

You can use curl or bash depending on the command available on your device.

These commands will clone the nvm repository to a ~/.nvm directory on your device.

2. Update your profile configuration

The installation process from step 1 should also automatically add the nvm configuration to your profile. If you’re using zsh, that would be ~/.zshrc. If you’re using bash, that would be ~/.bash_profile…or some other profile.

If it doesn’t automatically add nvm configuration, you can add it yourself to your profile file:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

This command above loads nvm for use.

3. Reload the shell configuration

With your profile configuration updated, now you will reload the configuration for your terminal to use:

source ~/.bashrc

With this command executed, nvm is ready for you to use. You can confirm that nvm is installed correctly by running:

nvm -v

This should show the version of nvm installed.

Wrapping up

With nvm installed, you can now install, uninstall, and switch between different Node versions in your Windows, Linux, or Mac device.

You can install Node versions like this:

nvm install latest

This command will install the last version of Node:

nvm install vX.Y.Z

This will install the X.Y.Z Node version.

You can also make a version your default by running:

nvm alias default vX.Y.Z

And if you want to use a specific version at any point, you can run the following in your terminal:

nvm use vA.B.C

NVM makes it easier to manage multiple versions of Node.js across different projects that require different versions.



Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Notice: If you’re trying to troubleshoot a problem, see the common issues page.

So you’ve decided to try out NVM for Windows, or at least learn more about it. Awesome. You can hack on it or build from source if you want to.

Installation

The easiest way to get started is to use the installer. This is found in the releases. The file is called nvm-setup.zip, which contains nvm-setup.exe.

Manual Installation

If you need to install manually, there is a separate download called nvm-noinstall.zip. You should also uninstall any existing versions of node.js.

  1. Download nvm-noinstall.zip. Extract this to the directory where NVM should be «installed». The default directory used by the installer is C:\Users\<username>\AppData\Roaming\nvm, but you can use whatever you like.

The zip archive contains three files, including nvm.exe, elevate.vbs, and elevate.cmd. All three of these are required for NVM to function properly. The «elevate» scripts help elevate administrative permissions for actions that require it. This is a critical component for switching between versions of node.js.

NVM for Windows «switches» versions of node.js by updating a symlink, using the mklink command.
The symlink is recreated to point to whichever version of node.js should run. This process requires
elevated administrative permissions.

  1. Update the system environment variables.

There are two system environment variables that need to be created, and one that needs to be modified.

First, add a new environment variable called NVM_HOME. This should be set to the directory from step 1. If you used the default, this would be C:\Users\<username>\AppData\Roaming\nvm.

Second, add a new environment variable called NVM_SYMLINK. This should be set to the path that will be used to identify which version of node.js is running. THIS DIRECTORY SHOULD NOT EXIST. It will automatically be created and maintained by NVM.

Finally, update the system path by appending %NVM_HOME%;%NVM_SYMLINK% to the end. The result should look something like:

Env Vars

User Variables: While not explicitly required, these same changes can be applied to the user environment variables as well. This can simplify use of nvm in the console without restarting Windows.

  1. Create settings.txt in the installation directory.

NVM for Windows stores configuration details in a simple text file. The example settings.txt contains an example that will work with the latest version.

The key attributes of this file are:

  • root: This is the installation directory where the files were extracted (NVM_HOME).
  • path: This is the symlink directory defined in NVM_SYMLINK.
  • proxy: Set this to «none». If you need to use a proxy, it can be modified using nvm from the command line.
  • arch: This should be 32 or 64 based on whether Windows is running as a 32-bit or 64-bit application.
  1. Test it, possibly restart.

If you chose not to set the user environment variables in step 2, you may need to restart Windows in order for it to recognize NVM in the path. If you did set the user environment variables, you don’t need to do anything else.

Type nvm in the console window. It should show the help menu. This is confirmation that NVM for Windows is successfully installed. Congrats, you did it by hand!

Uninstall

Have a look at the installation path — C:\Users\[username]\AppData\Roaming\nvm is the default path. In this folder you’ll find unins000.exe. Double-click it and agree to removing NVM and all Node-versions in the following steps.

Are you having trouble switching between different versions of Node.js as your build your project? Let Node Version Manager (NVM) save the day. Install NVM on Windows and save yourself the trouble of managing multiple Node.js versions.

Installing and using NVM can be a bit tricky, especially on Windows. But in this tutorial, you will learn how to install and use NVM on Windows to install different versions of Node.js.

Read on, and switch between Node.js versions without the hassle!

Prerequisite

This tutorial will be a hands-on demonstration. To follow along, be sure you have the following:

  • A Windows 10 computer with administrative privileges.
  • A code editor – This tutorial uses Visual Studio Code (VS Code), but you can use any code editor you are comfortable with.

How to Download and Install NVM on Windows

Switching between Node.js versions should not be complicated, and NVM is up to the task. But before you can use NVM, you must download and install it on your machine.

To download and install NVM:

1. Open your favorite web browser, navigate to the official download page on GitHub, and find the latest version of the installer. At this time of writing, the latest version is 1.1.9.

2. Scroll down to the Assets section of the GitHub page, and click nvm-setup.exe to download the NVM installer for Windows.

Downloading the NVM installer for Windows
Downloading the NVM installer for Windows

3. Once downloaded, double-click the installer to run it.

4. Now, choose the I accept in the Agreement option and click Next to accept the license agreement.

Accepting the license agreement
Accepting the license agreement

5. Select a location for NVM to be installed, and click Next.

Note the location, as you will need it later if NVM does not work correctly.

Selecting a location for NVM to be installed
Selecting a location for NVM to be installed

6. On the next screen, keep the settings as is and click Next. This setting lets you set the symlink directory, which is used to access NVM from the command line.

Setting the symlink
Setting the symlink

7. Next, click Install to begin installing NVM.

Installing NVM
Installing NVM

The installation process starts, and a status bar indicates progress.

Viewing installation progress
Viewing installation progress

8. Once installed, click Finish to close the installer.

At this point, NVM is now installed on your Windows machine.

Click Finish to close the installer.
Click Finish to close the installer.

9. Lastly, open PowerShell as administrator and run the below command to check NVM’s version installed.

If NVM is installed correctly, you will see the version number of NVM printed on the screen, as shown.

Checking the NVM version
Checking the NVM version

Configuring the PATH Environment Variable for NVM

The nvm command should successfully return NVM’s installed version. But what if you got an error instead, like the one below?

Getting a ‘cmdlet not recognized’ error
Getting a ‘cmdlet not recognized’ error

This error indicates the PATH environment variable is not configured correctly. The PATH environment variable is what tells your computer where to look for executable files like nvm.exe.

To fix this error, add the location of the NVM executable file to your PATH environment variable:

1. Run the below command to set the PATH environment variable for NVM.

Replace INSTALL_PATH with the NVM executable file’s path you noted in step five of the “Downloading and Installing NVM for Windows” section.

Setx path "%PATH%;INSTALL_PATH”

The output below shows setting the PATH environment variable for NVM is a success.

A restart might be required for the new PATH variable to take effect.

Configuring the PATH environment variable
Configuring the PATH environment variable

2. Now, run the below command to recheck the version number of NVM.

As you can see below, the nvm command now works in checking your NVM version.

Checking the version number of NVM
Checking the version number of NVM

Using NVM to Install Multiple Versions of NodeJS

Now that you have NVM installed and configured, you can use it to install multiple versions of Node.js side-by-side on your machine.

This feature is useful when working with projects requiring different versions of Node.js. For example, you can test a module you are developing without uninstalling the stable version of Node.js.

Installing the Latest Version of Node.js

When installing tools or any packages, typically, you would choose to get the latest version.

Run the below command to download and install the latest version of Node.js.

You will see a similar output as below, which shows the latest version of Node.js (19.0.0) installed on your machine.

Installing the latest version of Node.js
Installing the latest version of Node.js

Installing the Latest LTS Version of Node.js

The latest version of Node.js is not always the best choice for production environments. Why? The latest version might introduce breaking changes or might be unstable.

What are your other choices for installing Node.js? The Long Term Support (LTS) version of Node.js is most recommended for production environments. The LTS version is more stable and well-tested than the latest version.

Run the below command to install the LTS (lts) version of Node.js

Below, you can see the latest LTS version of Node.js installed, which is 18.12.0 at this time of writing.

Installing the latest LTS version of Node.js
Installing the latest LTS version of Node.js

Installing a Specific Version of Node.js

What if you need to install a specific version of Node.js? Worry not. NVM lets you choose which version of Node.js to install without overwriting over ones currently installed on your machine.

Installing a specific version of Node.js is often required when working on an older project that is incompatible with the newer version of Node.js.

Run the following command to list all versions of Node.js that are available for installation via NVM.

You will see a list of all the versions of Node.js that are available for installation below. Pick one version you wish to install.

Listing of all the versions of Node.js
Listing of all the versions of Node.js

Now, run the below command to install Node.js v16.18.0 on your machine. But you can replace v16.18.0 with your preferred version.

Installing a specific version of Node.js
Installing a specific version of Node.js

Switching Between Multiple Versions of Node.js

Perhaps you are working on a project that requires Node.js v16.x and another project that requires Node.js v18.x. If so, how do you switch between Node.js versions?

Luckily, you can use NVM to switch between these two versions as needed quickly.

1. Run the below command to see which version of Node.js is currently (current) in use.

Below, the output shows the current Node.js version in use is v16.18.0. Now all you need is the version you want to switch to. But first, you must check if that version is also installed on your machine.

Checking which version of Node.js is currently in use
Checking which version of Node.js is currently in use

2. Next, run the following command to list all Node.js versions that are currently installed on your machine. nvm list

You will get an output like the one below, which shows all versions of Node.js installed.

Listing all installed versions of Node.js
Listing all installed versions of Node.js

3. Finally, run the nvm use command below to switch to Node.js version 18.12.0. Replace 18.12.0 with the actual Node.js version number to switch to.

Switching to a different version of Node.js
Switching to a different version of Node.js

Running a Simple Hello World Program

Now that you have Node.js installed on your machine, you can try running a simple Hello World program to verify that everything is working as expected.

Create a new JavaScript file named hello-world.js

Create a new file named hello-world.js
Create a new file named hello-world.js

Open hello-app.js in your preferred text editor, add the following code to the file and save and close the editor.

The code below prints the string Hello World to the console.

var msg = 'Hello World';
console.log(msg);

Now, run the node command below to execute the *hello-app.js* script.

If all goes well, you will see the Hello World message printed on the console, as shown below. This output confirms that Node.js has been successfully installed on your machine.

Running a Simple Hello World Program
Running a Simple Hello World Program

Conclusion

Running and managing multiple versions of Node.js on the same machine can be a pain. But in this tutorial, you learned how to use NVM to install and manage different versions of Node.js on your machine.

Now that you have discovered how quickly you can switch between different versions of Node.js, would you consider NVM to level up your workflow?

NVM stands for Node Version Manager which is a tool used for installing Node.js and using the Node.js versions of your choice. It helps to switch between Node.js versions while also allowing to work with multiple NPM versions. It is easy to use and it works on any POSIX-complaint shell like bash, sh, etc. It supports operating systems like, Linux, macOS, Windows.  In this article, we will see how to install NVM in windows. 

Installing NVM in Windows

In this article, we will learn how to install NVM for Windows. Follow the below steps:

Step 1: Download the nvm-setup.zip from the assets table located over here. Unzip/Extract the contents (The Zip file should be present in the Downloads folder or the destination you choose to download) by extracting it to nvm-setup.

Download-the-nvm-setup.zip-file

Step 2: In the nvm-setup folder, double-click on the file named nvm-setup.exe as shown below.

Open-nvm-setup.exe-file

Step 3: Choose the I accept the agreement option and click on Next to proceed further with the installation.

License-agreement

Step 4: Now, select the destination to install and click on Next. 

Select-the-destination-location

Step 5: Select the folder in which setup should create the Node.js symlink, then click Next.

Set-Node.js-symlink

Step 6: Click on the Install button and once it completes, click on the Finish button.

Click-on-the-Install-button Click-on-the-Finish-button

Step 7: Confirm NVM is installed successfully by typing the following command in the terminal

nvm -v

Output: 

Verifying-the-installation-of-NVM

Last Updated :
11 Feb, 2022

Like Article

Save Article

  • How to install windows for ubuntu
  • How to install grub from windows
  • How to install mysql to windows
  • How to install windows for android
  • How to install grub for windows