Blog

  • Home /
  • Blog /
  • Taking Baby Steps with Node.js – Node Version Management with n

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

February 9, 2011

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.  

If you and your team want to learn more about how to write maintainable unit tests and get the most out of TDD practices, make sure to have look at our trainings and workshops or check out the books section. Feel free to reach out at infonull@nullprincipal-itnull.be.

Profile picture of Jan Van Ryswyck

Jan Van Ryswyck

Thank you for visiting my blog. I’m a professional software developer since Y2K. A blogger since Y2K+5. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Past organizer of the European Virtual ALT.NET meetings. Thinking and learning about all kinds of technologies since forever.

Comments

About

Thank you for visiting my website. I’m a professional software developer since Y2K. A blogger since Y2K+5. Author of Writing Maintainable Unit Tests. Provider of training and coaching in XP practices. Curator of the Awesome Talks list. Thinking and learning about all kinds of technologies since forever.

Contact information

(+32) 496 38 00 82

infonull@nullprincipal-itnull.be