Taking Baby Steps with Node.js – Node Version Management with n
Here are the links to the previous installments:
- Threads vs. Events
- Using Non-Standard Modules
- Debugging with node-inspector
- 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 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:
We can easily check which versions of Node.js that we have installed on our development machine by just executing the following command:
which outputs something like this:
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:
Changing the current active version of Node.js is as simple as executing the same command that we used for installing that particular version:
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”
Good stuff – keep it coming 🙂
Thanks for the post, this is helpful.
great help thanks
Comments are closed.