Wednesday, January 30, 2013

Using nvm to manage multiple active node.js versions

Today I had to install a different version of node.js on my laptop, because the program I wanted to try required a newer version than the one I had.

After googling a bit, I found nvm developed by Tim Caswell. It is a "simple bash script to manage multiple active node.js versions", (nvm stands for Node Version Manager). It helped me to quickly solve my problem.

I followed the installion instructions and in 3 steps I had the last version of node (v0.8.18) up and running.

This is what I did:

First I show you the very old version that was installed on my laptop for a previous pet project:
$ node --version
v0.5.11-pre
I cloned nvm repository from GitHub:
$ git clone git://github.com/creationix/nvm.git ~/.nvm
Initialized empty Git repository in /home/bscuser/.nvm/.git/
remote: Counting objects: 557, done.
remote: Compressing objects: 100% (327/327), done.
remote: Total 557 (delta 290), reused 471 (delta 219)
Receiving objects: 100% (557/557), 76.33 KiB | 8 KiB/s, done.
Resolving deltas: 100% (290/290), done.
And followed Tim's instructions by, first, sourcing the nvm.sh script
$ . ~/.nvm/nvm.sh
and then using nvm to install the current version of node
$ nvm install v0.8.18
######################################################################## 100,0%
Now using node v0.8.18
Once it finished, the node version was:
$ node --version
v0.8.18
As I plan to be using the program that needed this newer version of node for a while, I added the following lines to my .bashrc file:
. ~/.nvm/nvm.sh
nvm use v0.8.18
so I have the v0.8.18 version every time I open a console.

nvm has many other useful options that I plan to use. Thank you very much Tim for sharing it.

No comments:

Post a Comment