Installing Node Version Manager

Introduction

Before starting with Node Version Manager, aka NVM, a BIG THANKS to Corey Butler and Team, who made this cool product possible for Windows users. This tool can only be used on Mac and Linux machines. This tool is extended for Windows machines with a lot of effort and contribution from the community. Kudos to them.

Now lets get into the basics :). NVM is a tool that allows you to download and install multiple node versions and isolate the projects and packages without affecting their functionality. This way, installing or uninstalling a particular node version will not disrupt the packages and runtime. This article contains installation instructions for Windows 10. The same steps can be performed on Windows 11 as well.

Why NVM?

When working with SPFx, you may get into a situation where the solution needs to be tested in the Node LTS version (Long Term Support). Imagine you have developed an SPFx solution using node six and deployed the package in production. Now you are on node 10. You need to implement an enhancement for the solution developed in Node 6. There are two ways to achieve it; the harder way and the smarter way.

The harder way is to uninstall the current node version (which is 10 in this case), install the node version 6, develop the enhancement build, and package it. In this case, if you want to move to the latest version of the node, you need to again uninstall the legacy and install the latest version. Switching between node versions is a bit cumbersome and manually requires uninstalling / Installing to switch back to the required node version.

The smarter way is to install the NVM (Node Version Manager). This tool, when installed on your machine, will switch to the required node version with a simple one-liner command. How cool is it? 😊

This tool manages all legacy and newer node versions independently and manages the runtime for you on the fly.

As you see in the above picture, NVM can maintain multiple versions of nodes in the same environment/machine. Each version of a node can have its node runtime, tools, and generators.

Steps to install NVM

Installing NVM on Windows 10 is straightforward. All you need to do is download the MSI package and install it. Before installing NVM, validate that no previous version of NVM has been installed.

The screenshot shows NVM is not recognized as an internal or external command.

Step 1. Go to the below link and get the latest version of NVM (Node Version Manager)

Step 2. In the resulting folder, go to the assets section and click on the nvm-setup.zip file.

Installing Node Version Manager

Step 3. Download the file and unzip it. Right click on the installation file and select ‘Run as Administrator’. Please note that local admin rights or privileged admin rights are required to complete the proper setup.

Step 4. Select ‘I accept’ and click ‘Next’.

Step 5. You can either change the location of the folder or change it to your required one.

In some cases, the node installers may not have elevated rights to the default location, which is c:\users\username\AppData\Roaming\nvm. In this case, i have changed to c:\install\nvm

                                                                                      

Step 6. In the next window, it will ask for the location of the symlink that needs to be created for node.js. Symlink stands for symbolic link, which is used to load the required node modules for your project during the runtime.

In some cases, the nvm may not have access to the default folder path to create packages, in this case c:\Program Files \nodejs. 

Step 7. Finally, click on ‘Install’, and that will finish the installation of NVM on Windows 10.

Validation

After the installation of NVM, simply open the command prompt and type nvm.

Now you should see it. It will say the version it is running and also gives some helpful commands to get started.

Validation

To validate the successful installation of nvm, I have tried to run the following steps. 

Step 1. Run the version command to get the version   

nvm version

Step 2. Try installing a specific node version. In this case, I tried to install the node version v14.15.0 as this is the version supported by the SharePoint framework (at the time of writing this blog).  

nvm install 14.15.0

When you see the message 'Installation complete' it confirms that the installation of the node version is completed successfully. 

Step 3

Validate the node that is installed. After the installation is complete, if you enter 'node', you might end up getting the following error. 

'node' is not recognized as an internal or external command. Before testing the node version, enter the below command, telling nvm to use the particular node version, in this case, 14.15.0.

nvm use 14.15.0

Now validate the node version by entering the below command.

node -v

Basic commands

Command Description
nvm version It gives the version of NVM installed
nvm list Lists the different versions of the node installed
nvm current Displays the currently active version
nvm install latest Installs the latest version of the node available in the NodeJS repository
nvm install 14.15.0 Installs the node version of 14.15.0, which is available in the NodeJS repository. You can install the available node versions by specifying the node version.
nvm install lts To install a long-term support version of the node

Check the github documentation in references for more commands.

Switching to a different node version

By following the above installation steps, I managed to get different node versions.

Step 1. To get the list of available node versions, use the following command in the command prompt.

nvm list

The star denotes the active version currently being run.

Step 2. To switch to a different node version, for instance, 14.15.0, run the following command.

nvm use 14.15.0

Step 3. Validate the node package isolation. Since I am running node 14.15.0, the generators yeoman, pnp/sp, and gulp are specific to this node version only.

If I switched to a different node version, observe that yo is no longer available in that version unless manually installed.

Issues

Issue 1. could not be found or does not exist. Exiting.

When trying to install a particular node version, I am getting the following error.

c:\Users\username\AppData\Roaming\nvm could not be found or does not exist. Exiting.

Issue 2. The system cannot find the file specified

Users are getting the below message when trying to install the latest version / any particular version. 

Error open C:\insall\nvm\settings.txt: The system cannot find the file specified. 

Installing Node Version Manager

Issue 3. Error while creating node.zip. Access is denied. Could not download node.js

Users are getting the below message when trying to install the latest version / any particular version. 

Error while creating c:\users\username\AppData\Roaming\nvm\v17.8.0\node.zip - open c:\Users\UserName\Appdata\Roaming\nvm\v17.8.0\node.zip: Access is denied. 

Fix

If you end up having any of the above issues, please validate the below steps. Observe the instructions carefully, as this step is very important in fixing the majority of issues being faced while installing node versions. 

Step 1. Go to the folder path where the nvm is installed. The default location is c:\Users\<username>\Appdata\Roaming\nvm. In this scenario, I have installed under c:\install\nvm (refer to step 5 in the installation section). Check if the 'settings' file which of type text (.txt) exists or not. If not, try manually creating a settings.txt file with the following details. Please note that you may have to update the values based on setting the installation path for nvm and symlink. 

#replace the root value with nvm install folder path 
root: C:\install\nvm
#replace the path value with symlink install folder path 
path: C:\instsall\nodejs

Finally, save the file. 

Issue 4. Unable to switch to a different node version:

When trying to switch to a different node, I am getting the following error.

exit status 1: You do not have sufficient privilege to perform the operation.

Fix. This is due to the normal command prompt not having privileges to switch the runtime. Please open the command prompt in administrative mode.

Conclusion

Thus, in this article, we have seen what NVM is, why it is required, how to install nvm, and how to manage different node versions using NVM. 

References

Up Next
    Ebook Download
    View all
    Learn
    View all