Running Multiple Versions of Node.js with Node Version Manager
If you work on multiple Node.js projects, you’ve probably run into this one time or another. You have the latest and greatest version of Node.js installed, and the project you’re about to work on requires an older version. In those situations, the Node Version Manager (nvm) has your back, allowing you to install multiple versions of Node.js and switch between them as you see fit.
Getting started
To get started, you will need to install the Node Version Manager, or nvm
on your system. It is included by many package managers, or you can install it manually by running one of the following:
Once installed, you will also need to add a couple of lines to your shell’s startup file (.bashrc
, .bash_profile
, .zshrc
, et cetera):
Don’t forget to reload your configuration by source
ing the file, or simply closing and reopening your favorite terminal application.
You can also opt to paste those lines directly into your terminal each time you’d like to use nvm
.
Installing Multiple Node.js Versions
Now that we have everything installed, let’s install a few different versions of Node.js:
Upon running each command, nvm
will download the version of Node.js from the official website and install it. Once installed, it will also set the version you just installed as the active version.
If you were to run node --version
after each of the aforementioned commands, you’d see the most recent version of the respective major version.
nvm
isn’t limited to major versions either, you could also run nvm install 12.0.0
to explicitly install the 12 dot oh dot oh version of Node.js.
Listing Installed Node.js Versions
With a handful of different versions of Node.js installed, we can run nvm
with the ls
argument to list out everything we have installed:
Yes, as a matter of fact, I do have a bunch of different versions installed. Obviously, your output will probably look a little different than my own.
The little ->
indicates the active version, and default ->
indicates the default version of Node.js, the one that will be available when you open a new shell.
system
corresponds with the version of Node.js installed outside of nvm
on your system.
Setting a Default Node.js Version
Even with juggling multiple versions, there’s a good chance you have one version that you would prefer to run the majority of the time.
Often times, that would be the latest stable version of Node.js, leveraging nvm
for being able to tap older versions.
To set the latest stable version as your default, run:
If you’re like me, you have a specific version number you would like to set as your default. To alias default to a specific version, run:
Now every time you open a new shell, that version of Node.js will be immediately available.
Switching Between Node.js Versions
What good are all these versions of Node.js if we can’t switch between them?
To switch to a different version of Node.js, simply tell nvm
which version you’d like to use
:
You can even switch back to your default version:
Removing Node.js Versions
As you saw earlier, I have a bunch of different versions of Node.js installed due to working on a variety of projects over the past year on this particular laptop.
Between you and me, I don’t even remember which projects I had installed some of those versions for.
Fortunately, we can remove Node.js versions just as easily as we installed them:
Unfortunately, when you specify a major or minor version, nvm
will only uninstall
the latest installed version that matches the version number.
Because I have 2 different version of Node.js version 6 installed, I have to run the uninstall
command for each version:
Worth noting, you can’t remove a version of Node.js that is currently in use and active.
Unloading Node Version Manager
Had enough and want to get back to your system’s installed version of Node.js?
You could simply switch the system
version the same way we switched to other versions by running:
Yes, my system is a bit behind right now.
Or if you’d prefer to unload nvm
entirely for your session, you can simply run nvm unload
.
Conclusion
Working on multiple projects that utilize different versions of Node.js doesn’t have to be a nightmare.
Node Version Manager makes the process quite painless and even takes the headache out of remembering to switch versions by supporting automatic switching by way of an .nvmrc
file in your project’s root:
Just remove multiple files on mac. Make its speed fast and remove all unwanted apps and malware. Download the uninstaller for mac and clean your mac memory and create a large space on it.
ReplyDeleteUse best mac uninstaller and remove multiple application easily in few clicks.
ReplyDelete