There are a number of reasons you would need to install multiple versions of node.js on one machine. Perhaps you need to test your node applications with different versions of node. Or maybe you just want to try out the latest, bleeding-edge version of node without having to uninstall your current version. In any event, wouldn't it be great if you could do all that? Well, as it turns out, this is relatively easy thanks to the nvm (Node Version Manager) project. It allows you to easily install and manage multiple different versions of node.
This article was written specifically for Ubuntu, but if you're using a different linux distribution, you can probably still follow the instructions here, except with a few minor changes to match your distro's way of doing things.
The first step towards installing nvm is to download the latest release:
wget https://github.com/creationix/nvm/archive/v0.10.29.tar.gz ~/
Version 0.10.29 of nvm is used here, because it was the latest release as of the time this article was written. You may want to check for the latest release.
Unpack the gzipped archive you just downloaded:
tar -zxvf ~/v0.10.29.tar.gz
Rename the directory that was just created:
mv ~/nvm-0.10.29 ~/.nvm
Run the installation script:
Add the following to the end of the ~/.bashrc file:
Close and re-open the terminal window.
Verify that nvm was installed correctly:
Should output the version number of nvm, like this:
In case nvm needs to build a version of node from source, you'll want to install the build dependencies:
sudo apt-get install g++ make
Install Different Versions of Node.js
Now that you have nvm installed, you can install a specific version of node.js like this:
nvm install v0.10.29
This will take a little while.
Once the installation of v0.10.29 is complete, try installing another version:
nvm install v0.8.27
You can view a list of node.js versions that you have installed like this:
To switch to a specific version of node:
nvm use v0.10.29
To set an alias:
nvm alias 0.10.x 0.10.29
To set the default node version:
nvm alias default 0.10.29
Well, that's about it. If you have any questions or need help debugging, try the nvm GitHub repository for more information.