When working with Node.js , you might encounter situations where you need to install multiple versions of the runtime. For example, maybe you have the latest version of Node set up on your machine, yet the project you are about to start working on requires an older version.or may be you are upgrading an old Node project to a more modern version and it would be handy to be able to switch between the two while you make the transition.
Without a good tool, this would mean spending too much of time manually uninstalling and reinstalling Node versions and their global packages. Fortunately, there is a better way.
Introducing NVMNVM stands for Node Version Manager. It is a great tool that helps you to manage and switch between different Node versions with ease. It provides a command line interface where you can install different versions with a single command, set as default, switch between them, and much more.
OS SupportNode version manager supports both macOS and Linux, but that is not to say that Windows users have to miss out. But there is a second project named nvm-windows that offers Windows users the option for easily managing Node environments.
The basic commands listed below (for installing, listing, and switching between versions) should work for both nvm and nvm-windows.
RequirementsAs it is likely that you have Node.js installed as the default installer of the official website, you need to uninstall it. Else you will have conflicts with the installed versions later.
After uninstalling, you then need to remove every possible installation directory that may remain on the disk (C:\Program Files\nodejs). upon verifying that the mentioned directory does not exist anymore, install any possible npm install locations too.
1. %USERPROFILE%/AppData\Roaming\npm (C:\Users\
2. %USERPROFILE%/AppData\Roaming\npm-cache (C:\Users\
After deleting the mentioned directories and the content, you may then proceed with the NVM installation for Windows.
InstallationHow to do ‘Node.js install’ for Linux, macOS, and Windows.
Windows:1. Uninstall any existing versions of Node.js
2. Delete any existing Node.js installation directories, such as C:\Program Files\nodejs
3. Delete the existing npm install location, such as C:\Users\
After this, download and run the latest stable installer and you are all set to go!
macOS/Linux:Unlike Windows, removing previous Node and npm installations in macOS and Linux is optional. However, if you want to remove them, there are plenty of good resources available online.
You can install nvm using cURL or Wget.
On your terminal, run the following:
With cURL -
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
With Wget -
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.35.2/install.sh | bash
This will clone the nvm repository to ~/.nvm and will make the required changes to your bash profile, so that nvm is available from anywhere in your terminal.
Then, reload or restart your terminal and nvm is ready to be used.
Ensure that nvm was installed correctly by running with
nvm --versioncommand which would return the version od nvm installed.
Using nvmIf installed correctly, the nvm command is available anywhere in your terminal. Let’s see how to use it to manage Node.js versions.
Install Multiple Versions of Node.JSOne of the most important parts of nvm is to install different versions of Node.js. For this, nvm provides the nvm install command. You can install specific versions by running this command followed by the version you want. For example,
nvm install 12.14.1
By running the above in a terminal, nvm will install Node.js version 12.14.1.
Nvm follows SemVer, so, if you want to install, for example, the latest 12.14 patch, you can do it by running,
nvm install 12.14
Nvm will then install Node.js version 12.14.X, where X is the highest available version. You can see the full list of available versions by running:
For nvm-windows, this is:
nvm ls available
npmWhen installing a Node.js instance, nvm will also install a compatible npm version. Each Node version might bring a different npm version, and you can run npm -v to check which one you are presently using. Globally installed npm packages are not shared among different Node.js versions, as this could cause incompatibilities. Rather, they’re installed alongside the current Node version in ~/.nvm/versions/node/
Fortunately, when installing a new Node.js version, you can reinstall the npm global packages from a specific version. For example:
nvm install v12.14.1 --reinstall-packages-from=10.18.1
By running the above, nvm will install Node.js version 12.14.1, the corresponding npm version, and reinstall the global npm packages you had installed for the 10.18.1 version.
If you’re not sure what the latest version is, you can use the node alias:
nvm install node
This will currently pull in version 13.6.0.
Or you can install the most recent LTS release, using:
nvm install --lts
This will currently pull in version 12.14.1.
You can also uninstall any instance you no longer think is useful, for example to uninstall Node.js version 11.10.1, run the command: nvm uninstall 11.10.1
Switching Between Node.js VersionsTo switch to a different version of Node.js, use the nvm command use followed by the version of Node.js you would like to use:
nvm use 0.10
This is the output you will see:
Now using node v0.10.48 (npm v2.15.1)
You can even switch back to your default version:
nvm use default
At this point, you have installed several versions of Node.js. You can use nvm to uninstall any unwanted version of Node.js you may have.
Removing Node.js VersionsYou may have several versions of Node.js installed due to working on a variety of projects on your machine.
Fortunately, you can remove Node.js versions just as easily as you installed them:
nvm uninstall 0.10
This is the output that will display after running this command:
Uninstalled node v0.10.48
Unfortunately, when you specify a major or minor version, nvm will only uninstall the latest installed version that matches the version number.
So, if you have two different versions of Node.js version 6 installed, you have to run the uninstall command for each version:
It’s worth noting that you can’t remove a version of Node.js that is currently in use and active.
You may want to return to your system’s default settings and stop using nvm. The next step will explain how to do this.
Unloading Node Version ManagerIf you would like to completely remove nvm from your system, you can use the unload command:
If you would still like to keep nvm on your system, but you want to return to your system’s installed version of Node.js, you can make the switch by running this command:
nvm use system
Now your system will return to the installed version of Node.js.
ConclusionWorking on multiple projects that use different versions of Node.js doesn’t have to be a nightmare. Node Version Manager makes the process seamless. It enables a concern-free installation and easy switching between different versions, saving time for what really matters.
What OdiTek offers
Refer our Skills page:
We had a tough deadline to launch our .Net based application that processes a lot of data, and got very frustrated with our development agency we hired. Fortunately we got Oditek, and they took over seamlessly the product development, launched the app & continued feature development. Just awesome!
They were very attentive to our needs as clients and went out of the way to make sure our projects were taken care of. They were always able to get projects done in the specifications we requested. They are passionate about getting things done; I would definitely recommend them to lead any IT projects.
I worked with OdiTek on few high profile banking application projects. They did a fantastic job with web applications & manual testing on the VAS apps for two leading banks of UK that included rigorous UAT phases. I recommend them for any application development where security matters.
OdiTek is our extended team who works on our key software projects. They are dependable, good in collaboration and technically very much to the level what we expect a global team should be. They had transformed our web applications, CRM and added mobility to existing business platforms here.
It's been more than 4 years now that we are working with OdiTek on our cloud based web product development. It's been amazing working together, they are very competent on designing scalable, high performance apps. Their technical support is outstanding to say the least, even at odd hours.
I am a fan of Team OdiTek since 2014 and have worked on many product development projects together. Specially worth mentioning their deliveries on VAS Banking web application development & manual testing services for Smarta, UK. They are highly skilled & a professional team to work with.
OdiTek has been working on our Integrated Web-scale Mobile Platform i.e. Optimal Health since 2014. They are very professional and takes care of the requirements meticulously. They are technically very sound and sincere in ensuring quality & performance. Wonderful working with them!
You can trust the team, with minimum supervision you get the work done. They are honest, professional & committed to schedule & quality. I had been successfully running 3 business applications designed, developed and maintained by Oditek developers. It’s been a pleasure working with them.
OdiTek has been working in custom software development, including services for test automation. Many of them have worked with me in 2009-10 when I was R&D Manager in NetHawk India. They have great enthusiasm & a passion to excel in bringing customer success. Their work has been very impressive.
It's amazing to see these guys are turning their experience into a global delivery excellence at OdiTek. I am sure their past large scale product development experience will be handy to product companies. I would always recommend Oditek for software development, especially performance-driven solutions.