How to setup a node.js development environment on Ubuntu 11.04

Install the latest node.js via apt-get

There are several ways to setup a node.js development environment on Ubuntu, you can either choose to download and compile it form source or using apt-get to do the works for you. Because node.js is still a pretty young project, it updates frequently. I suggest installing node.js via apt-get. You will find it is much easier not only to install but also update it. If you are on a Mac you can check out this post for the instruction.

Edit 2011/12/18

I’ve found it’s easier to install node through nvm, a node version management system. It’s something like rvm for ruby. You can switch between node versions for development. Also npm now come with node since version 0.6.3 which means you don’t have to install it by yourself. So basically you can ignore the Install npm step.

Install node.js

The problem is the version of node.js on apt-get is outdated. Therefore we need to add repository to apt ourself.

Install npm

npm is the most popular package manager for node. It is like gem for ruby and pear for php. There are thousands of packages available out there including ORM, router, third party api wrapper … etc. So before you write your own solution make sure to check if it is already there on npm.

$ curl http://npmjs.org/install.sh | sudo sh

Install mongodb

mongoDB is my number one choice NoSQL database for node.js. It is not the fastest but the easiest to use especially for people used to work with relational databases. However please do not design your data structure as what you used to have for a relational database. Otherwise your node.js app will run slow. Please do checkout their awesome docs before you start.