How to install NVM for Windows

This post will be a guide to install NVM for Windows if you want to use it with multiple user accounts. If you have worked with node.js then you may be familiar with node version manager (NVM). It allows you to have several versions of node installed on your machine. It also provides tooling that lets you easily switch between different versions. The catch for NVM is that it only works on POSIX-compliant shells (sh, dash, ksh, zsh, bash), on UNIX, macOS, and Windows WSL (Windows Subsystem for Linux).

https://github.com/nvm-sh/nvm

But where is the love for Windows!?

Windows 10 image

All jokes aside, if you are developing on a Windows machine, you still have options! Additional options include setting up Windows WSL and installing NVM under whichever distro you choose (that will be a topic for another blog post), or you could use a similar but different application called NVM for Windows.

https://github.com/coreybutler/nvm-windows

I highly recommend using NVM for Windows for all of my SharePoint Framework (SPFx) developers out there. This will allow you to easily switch between developing solutions for SharePoint Server 2019 and SharePoint Online due to the fact that the on-premises version of SharePoint requires you to use older versions of node.

I’m also going to start off by saying this: If you are the only user on your machine and your account has administrator privileges, you can install NVM for Windows with either the default settings or how we will do it below and it will function the same way.

We are going to walk through installing and configuring NVM for Windows in a non-default location. This approach has its advantages that have worked well for me which I will discuss below.

Why take this approach?

  • You want a single point of access for tools and configurations that can be used by multiple accounts on one machine.
  • If you work in an environment where the computers are locked down or they do not want you messing with anything in Program Files.
  • You don’t want to be forced to use your administrator account for everything.

Here is a scenario: I am the only developer using this machine however I have two accounts. One normal account for everyday use and one that has administrator privileges. If I use my admin account to install NVM for Windows, by default it will put everything behind the admin account’s user directory making it inaccessible from my normal account. This would lock me into using my admin account for daily development, which I am trying to avoid.

NVM

This behavior is by design as NVM for Windows is intended to be scoped to the user and these are two different user accounts, even though both accounts are mine. Also, any global dependencies that I install would only be available to my admin account (remember NVM is user scoped). I know we could work around this by digging into the permissions but since I am the only developer using this machine in this hypothetical situation, I want to have the same set of tools, files, and configuration in a single location that is easily accessible by both accounts so let’s walk through my setup.

You will need to use an administrator account in this process as you will be creating symbolic links (symlinks), which must be done with administrator privileges in Windows.

Note: It occurred to me that you may be able to work around having to use an elevated UAC context by enabling “Developer Mode” in Windows 10, which would allow users to create symlinks, however due to security concerns, that was not an option with the customer I was working with so I have not tested this approach.

Windows 10 Developer Mode option
Windows 10 Developer Mode option (you can enable option using an administrator account)

Important points to know before installing NVM for Windows

NVM for Windows (which I will refer to from here on as NVM) will create a symlink called “nodejs” in your Program Files directory by default (we are going to change this location later, but it defaults to Program Files).

C:\Program Files\nodejs

NVM will create a directory called “nvm” under your user’s hidden AppData folder (we will change this location as well, but it defaults to the Roaming folder under AppData).

C:\Users\james.carson\AppData\Roaming\nvm

This is also where you will find all the versions of node you have installed.

NVM will create 2 system environment variables

NVM_HOME // path to the nvm folder
NVM_SYMLINK // path to the nodejs symlink

The “path” system variable will also reference both environment variables

%NVM_HOME%
%NVM_SYMLINK%

You can test each of these by copying and pasting the variables above in File Explorer and seeing where it takes you. You should expect to navigate to the paths listed above.

Install NVM for Windows

I’m going to create a folder called tools on my C drive where I will end up putting everything. Right-click and create a new folder or use mkdir from the command line to make a new directory.

C:\tools

Next, we will want to download the latest release of NVM for Windows which at the time of writing is v1.1.7.

https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-setup.zip

You will want to right-click and extract the nvm-setup folder.

Browse to the nvm-setup folder and double click nvm-setup.exe to run the installer.

Accept the license agreement and click Next

Install NVM for Windows license screen

Change the location to add a nvm directory to the tools directory we created earlier. The new entry should be C:\tools\nvm and click Next.

NVM for Windows installation destination location
C:\tools\nvm

Change the path of the nodejs symlink to C:\tools\nodejs

NVM for Windows installation symlink location
C:\tools\nodejs

Verify that the installation location is: C:\tools\nvm

Confirm install NVM for Windows and location

Click Install and Finish once complete.

If you look back in the tools directory we created, you will see the nvm folder and the nodejs simlink. If/when we need to make changes (hint: future blog post), these files are easily accessible.

Location of NVM installation: C:\tools

Using NVM

Test the NVM installation by opening a PowerShell terminal and typing:

nvm --version
NVM for Windows PowerShell command: nvm --version

Install a version of node to your local machine.

nvm install 14.17.4

Set NVM to use the version of node you just installed. This command requires elevated privileges as this is where the symlink gets created/updated.

nvm use 14.17.4

You can test your installation by running the command below to get the current version of node

node --version

This command will list all of the currently installed versions of node. Use the “nvm use” command above to select a specific version. Add the available argument to list available versions.

nvm list
NVM for Windows PowerShell command to list versions of node
List available versions of node.js

Additional helpful commands

You can verify that your NVM_HOME and NVM_SYMLINK environment variables are pointing to the correct directory (C:\tools\nvm) and symlink (C:\tools\nodejs). The installer initially sets these values for you. You can check them by running the PowerShell command below.

Get-ChildItem -Path Env:NVM*
Verify install of NVM for Windows via PowerShell to check environment variables

Here is a command I frequently use to make symlinks in Windows. You shouldn’t need it here though because NVM makes symlinks for you. You will need to open a command prompt (CMD) as administrator for this to work.

mklink /D C:\tools\nodejs C:\tools\nvm\v14.17.4
mlink command
Additional mklink options and don’t forget put quotes around paths that have spaces!

This is how I install NVM for Windows and use it with multiple user accounts. Now you can use your normal account for any development work and use your admin account to hop between different versions of node. Also, having everything in one central location will come in handy later if we need to modify configuration files or when we start installing additional tools.

A huge thank you to the person who made NVM for Windows for making our lives much easier when working with different versions of node.js on Windows!

Cheers!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.