Managing Multiple Versions of Node.js
A Short Tutorial on Node Version Manager

Categories:
What is Node Version Manager
Node Version Manager is one of my favorite CLI tools. As stated on the project’s git repository, it is a:
POSIX-compliant bash script to manage multiple active node.js versions
NVM makes it easy to have multiple versions of Node.js installed at once on your system and provides a simple CLI interface for switching between them.
Why Use Node Version Manager
If you are working on different Node.js projects on the same machine, each project will likely have its own requirements for which version of Node.js you must use to run it.
By using NVM, you can reduce complexity related to managing these versions.
Installation
Installing NVM is super simple thanks to the provided install.sh script.
All you need to do is grab the script, run it, and source your updated dotfile (usually .bashrc).
Downloading the script
If you have curl or wget installed on your machine, you can grab the script and run it via this one-liner. Don’t forget to update the version number to your desired release.
| |
Ensuring NVM is in your $PATH
The install.sh script automatically makes changes to your dotfile(s) so that your shell can load NVM and manage Node.js versions correctly.
After you have run the script, all you need to do is open a new shell session.
If you would like to remain in the current session, you can source your updated .bashrc file.
| |
Verifying Installation
To verify that NVM was successfully installed on your machine, you can run:
| |
Installing Node.js with NVM
At this point, you are now ready to use the tool to install a version of Node.js.
To install the LTS version of Node.js, simply run:
| |
Listing Installed Versions of Node.js
If you would like to check what versions of Node.js are installed on your local machine, you can use:
| |
This will return output similar to the following:
| |
In the above example, v22.18.0 is the only version I have installed. It is also the version NVM is using by default.
What’s Not Installed
In the above output from nvm ls, there are a lot of lines that may seem confusing. Let’s clarify what is going on here.
Anything that shows -> N/A is not installed locally. These are just LTS aliases that NVM could install if you ask.
Switching Between Versions of Node.js
After you have installed more than one version of Node.js on your system, you can use nvm to switch between them at any time:
| |
Using a .nvmrc File to Pin Node.js to a Project
In the root directory of your project, you can create a .nvmrc file containing the version of Node.js you would like to pin to the project.
A .nvmrc file is just a text file that contains a version of Node.js.
For example, this would be the contents of a .nvmrc file using a version number.
| |
If you would like to use an alias instead, the contents would be something like the following:
| |
This enables you to simply switch to the pinned version by running nvm use in the directory containing the .nvmrc file.
Uninstalling a Version of Node.js
Using NVM to uninstall a local version of Node.js is simple. All you need to do is run:
| |
Wrapping Up
NVM simplifies Node.js version management, letting you focus on building projects instead of wrestling with environment conflicts.
It is not the only tool out there for the job, but has been my go-to over the years.