This article was peer reviewed by Tim Severien. Thanks to all of SitePoint's peer reviewers for making SitePoint content the best it can be!
When developing Node.js applications you might face situations where you need to install multiple versions of Node. This can happen when you have multiple projects and they have different requirements, or you have a deployable application which must be compatible with different Node versions. Without a good tool this would mean a lot of work and effort to install the different versions manually, and basing a project on a specific version. Fortunately there is a better way!
[author_more]
Introducing nvm
nvm stands for Node Version Manager. As the name suggests, it helps you 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 a default, switch between them and much more.
This tool is especially useful when you have to troubleshoot issues for projects where the user has a different Node version installed than you. With nvm you can switch to the client's Node version with one command, start the application and get to the issue. The node
command from that point onward will point to the version you've specified. Otherwise, you'd have to do it manually, which would mean installing it in a location on your system and starting the application to target the executable of that installation.
Installation
Installation differs for Windows and non-Windows systems. nvm doesn't officially support Windows, but fortunately there's a side project nvm-windows—ironically written in Go—which offers an installer as well as a stand-alone version for Windows users.
Windows Installation
First, make sure you uninstall any Node.js version you might have on your system, as they can collide with the installation. After this, download the latest stable installer. Run the executable installer, follow the steps provided and you're good to go!
OS X/Linux Installation
Removing previous Node installations is optional, although it is advised you do so. There are plenty of good resources online as to how you might do this (OS X, Linux). It is also good if you remove any npm installation you might have, since it might collide with nvm's installation. You'll also need to have a C++ compiler installed on your system. For OS X you can install the Xcode command line tools. You can do this by running the following command:
xcode-select --install
On Linux, you can install the build-essential package by running the following (assumes apt):
sudo apt-get update
sudo apt-get install build-essential
Having the required C++ compiler you can then install nvm using cURL or Wget. On your terminal, run the following:
With cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Or with Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Note that the version number (v0.31.0) will change as the project develops, so it is worth checking the relevant section of project's home page to find the most recent version.
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.
That's it, nvm is installed and ready to be used.
Continue reading %Quick Tip: Install Multiple Versions of Node.js using nvm%