Node Hack: handling multiple Node versions on Windows

Updated: Jan 23, 2020

A while back I got into the situation of needing to upgrade my current version of Node because of an Angular project I needed to work on. The version that I had, was strongly needed for a project I am working on at my job and without that specific version the project wouldn’t work (fun).


At first, I was a little lost because I didn't know it was possible to have simultaneous versions of node working on your computer, and there’s not; what does exist, it's a way of switching back and forth to the node version that you need by using a tool called nvm; unfortunately nvm does not support Windows, as it works only for Linux and MacOS.

Fortunately, there are 2 ways to enable node version managing on Windows:


In this blog I will detail how to setup nvm-windows, and nvm with WSL, and the benefits I found using one over the other.



NVM for Windows


nvm-windows, it’s a utility for handling multiple installations of Node JS on a Windows computer with no dependency on Node, which represents an advantage because of its independency of big breaking updates on Node that might brake the tool.


NVM for Windows comes with an installer, which you can download from the tool's Github page. After installing, everything is ready to go and version managing for Node it's a reality.


Before Installing


Remove all previously installed versions of Node and NPM, as well any installation folder you might have.


Installation


Install nvm-windows by downloading the most recent release. This will download a zip file containing the .exe wizard to complete installation.


Follow the steps in the installer.


In the following step, make sure that you install Node on the desired folder, in case you don't want it in the default one.


To verify installation succeeded, run the following:


Use


These are the most important commands to begin:

  • nvm install <version>: version is to specify the Node version you would like to install, or latest for the latest stable version. You can install as many as you need.

  • nvm list [available]: list the node.js installations.

  • nvm use <version>: switch to use the specified version that you need.

nvm-windows documentation is well equiped, and it contains everything you need to know to use all the features of this tool.



NVM with WSL


Another way of configuring a Node version manager on Windows, it’s to use nvm with WSL.


What is WSL?

WSL, Windows Subsystem for Linux, lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.

With WSL, you can use your favorite Linux distro and part from there to run command-line free software, run bash shell scripts and more.


nvm was created to work on Linux and MacOS computers, therefore by using WSL you are able to use nvm as your node version manager.


Installing WSL


Surprisingly, installing WSL it’s easy peasy, follow the steps on Windows Subsystem for Linux Installation Guide for Windows 10 to do so.


After installing it, proceed to open your WSL terminal and let's install nvm.


Install nvm


In order to install nvm, run the following install script. You may either download and run the script manually, or use the following cURL command:



Verify installation


Use


These are the most important commands to begin:

  • nvm install node: node it's an alias for the latest version of Node.

  • nvm install <version>: version is to specify the Node version you would like to install, you can install as many as you need.

  • nvm list: list all the Node available versions.

  • nvm ls-remote: list the Node installations you've made.

  • nvm use node: switch to use the latest version installed of Node.

  • nvm use <version>: switch to use the specified version that you need.



Conclusion


Managing multiple Node versions it's something we will at some point encounter when we're working with multiple projects simultaneously, and having a tool to do that for you lifts a heavy lift off your shoulders as a developer.


Both tools serve their purpose and work as intended, but here's 2 things I found really interesting about each solution.


NVM with WSL


In my specific case, I work remotely and I use my personal computer to develop the projects from work, as well as for personal projects; installing nvm with WSL allowed me to keep my local work environment clean and not jeopardize it by switching back and forth the node version. I do all I need on my WSL for my personal projects and my local work environment it's intact.


NVM for Windows


Something very interesting about nvm-windows, it's written in Go; which will prevent the tool from braking if there’s a big node upgrade in the future, like it’s the case of io.js and nvmw, both broken from major node updates. This adds a sense of reliability on this tool that maybe others don't have.


 

Hope this was of use, and helped you configure your Node version manager on your machine.


Resources and further reading

Windows Subsystem for Linux Installation Guide for Windows 10

Documentation for nvm

Documentation for nodist

Documentation for nvm-windows

48 views