Running multiple versions of Node.js

Just like Ruby, with its rbenv and rvm, Node.js has its own version management system. The node.js eco system and community is growing at speeds we would never imagine. Seldom, but sometimes libraries simply can´t keep up with the development of the node.js core, which propagates both for and against using a version manager.

In the perfect world (although close to it when it comes to node.js), we would of course always be using the latest version of the core. Then this subject would be irrelevant.

However, since we are not living in the perfect world and the needs of running multiple versions of the core stretches outside library dependencies this might be useful in some cases. In a staging/production environment this could be useful during an upgrade for example.

Node.js version management with hot n

Keeping it simple

And as many libraries and tools in the Node.js community, it is kept super simple solving one problem and solving it good.

no subshells, no profile setup, no convoluted api, just simple.

Installing n

n is the first thing you´d install after installing node (and the node.js package manager npm.

$ npm install -g n

Once installed, you have the possibility running multiple versions. Let´s say I want to have the latest official stable version 0.8.11:

$ n stable

(Roll your thumbs or go fetch a coffee...) BOOM!

Running node -v should now display v0.8.11 (or the current stable version).

Or why not do it hardcore, using the latest official release:

$ n latest

Or a specific version:

$ n 0.8.11

Specifying a node version in your package.json file would try using that version specific to that project.

And you can always override the version while executing a command with node using use like n use 0.7.1 index.js.

There we have it! So n will from now on serve as your main version manager for different node.js versions.