In my previous post, I explained how to install node and npm on OS X Mavericks using nvm.

We are now going to take a look at how to do the same on Linux.

Note: This procedure has been tested on Ubuntu 14.04 LTS but it should also work for different versions of Linux.

I have a Windows Azure virtual machine running Ubuntu 14.04 to host different websites and webapps. The idea is that, like me, you might want to use different versions of node for different appas. But using apt-get install nodejs will only give you the latest version.


Node Version Manager

For those familiar with Ruby, it is highly recommended to use a Ruby Version Manager such as rbenv or rvm. It works like a charm when you need to manage different version of Ruby and don't want to screw up the system version of Ruby.

It turns out that something similar exists for node! It is called nvm for Node Version Manager. The good news is that it is really easy to install!

So let's get started!

First, we need to clone the nvm repository:

$ git clone ~/.nvm

Then, we need to add the following line to our .profile, .bashrc or .zshrc:

$ echo "source ~/.nvm/" >> .zshrc

This allows us to use nvm in your shell. And that's it!

Installing node & npm

Installing nvm is not enough, we now need to install node & npm.

To print out the list of all the available versions, simply run:

$ nvm ls-remote

We want to install the current stable version which is v0.10.26, so we need to run:

$ nvm install -s v0.10.26

The -s flag means we want to compile node from source.

When the installation process is finished, our brand new node and npm will be installed!

The great thing with nvm is that you can use a different version of node in each of your shell instances. But if you want to stick to the latest version, you can set it as default by running:

$ nvm alias default 0.10.26

Make sure everything is up and running by typing node -v && npm -v.


That's all folks! You can now manage different versions of node/npm without even thinking about it. :)