Running multiple Node versions in a dev environment [#17]

Having multiple Node versions while building a system is a common use case. I have came across this when working with multiple Angular applications that are part of wider system, I constantly had to switch between Node versions to have the right one for the app I was working on. If you are wondering why all the app were not built using the same Angular version, it was because these Angular apps were built across a span of time of 4 years. These company had around 7 active Angular apps, some of them were built in version 4, others in version 5, and the most rescent ones in Angular 9.

You have a few options to overcome this issue. One posible approach for this is using NVM (Node Version Manager). NVM is a tool that allow you to Manage multiple Node versions in your dev environment.

Node Version Manager (NVM)

As the name of the tool indicates, NVM is a version manager for Node. Some of the operations that it allows you to perform are the following:

  • Install multiple versions
  • Switch between versions

Installing NVM

If you have installed Git for Windows you should be able to run the following command in the Git Bash console and get NVM installed. If not, I would recommend installing Git for Windows first. If you are using a Mac or Linux system you can find the details for the installation in the NVM repository.

Installing NVM in Windows

This command will install NVM, it should be run in a Bash console such as the one that comes with Git for Windows

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

I have ran into an issue while installing NVM in Windows in the past where I see that the NVM command is not available after the installation (I got a message "command not found"). After trying to resintall, I noticed that there was a message indicating that a file was missing: "...your system may not have ~/.bash_profile or ~/.bashrc files...". After creating a .bash_profile in the root of my user's fodler I was able to run the install command with success.

Common NVM operations

List Node versions available

List all the Node versions available for installation

nvm ls-remote
List Node versions installed

List all the Node versions that installed locally

nvm ls
Install a new Node version

Install a new Node version. Replace [version] by the Node version you wish to install.

nvm install [version]
Switch from one Node version to another

Switch from one Node version to another. Replace [version] by the Node version you wish to use.

nvm use [version]