Taking Baby Steps with Node.js – Node Version Management with n

Here are the links to the previous installments:

  1. Introduction
  2. Threads vs. Events
  3. Using Non-Standard Modules
  4. Debugging with node-inspector
  5. CommonJS and Creating Custom Modules

The community around Node.js is definitely thriving at the moment. As a consequence, new versions of Node.js are being released very rapidly. While the 0.2.x versions of Node.js are considered stable, the 0.3.x versions contain all the new features and latest enhancements. I usually develop against the more stable 0.2.x versions of Node.js while spiking the new stuff in the latest 0.3.x versions in order to get a feel of what?s coming. This means that we need to manage multiple versions of Node.js on our development box while being able to easily switch between the different binaries.

There are a couple of alternative solutions out there that deal with the issue of version management for Node.js. First, there?s nvm which is a simple bash script for managing multiple versions of Node.js. Then there?s also nave which is another shell script that basically does the same thing. But the solution that I?m currently using and going to discuss in this blog post is a tool called n.

We can very easily install n with npm by issuing the following command:

npm install n

Installing a particular version of node.js is a easy as executing n, specifying the version number:

n 0.2.6

n will get the source code for the requested version and automatically configures/compiles in order to get the binaries. The last version that gets installed this way also automatically becomes the active binary. If we just want to install the latest version of Node.js, we can also use the following command:

n latest

We can easily check which versions of Node.js that we have installed on our development machine by just executing the following command:

n

which outputs something like this:

   0.2.3

o 0.2.6

   0.3.7

You can also check the current version of node.js by executing the following command:

node — version

Running a Node.js application is still done using the same command as before:

node server.js

Changing the current active version of Node.js is as simple as executing the same command that we used for installing that particular version:

n 0.2.3

This switches the used version of Node.js back to v0.2.3. We can also run an application using a particular version, overriding the current active version:

n use 0.2.6 server.js

Removing a particular version is pretty easy as well. Just use the following command:

n rm 0.2.3

That?s it! Being able to quickly switch between the many different versions of Node.js has been a huge time-saver for me so far. 

Until next time.  

5 thoughts on “Taking Baby Steps with Node.js – Node Version Management with n

Comments are closed.

Proudly powered by WordPress | Theme: Code Blog by Crimson Themes.