You can consider this post an update to my prior post on installing Node.js on Ubuntu however I will also be installing NPM (which is a package manager for Node) and using a newer version of Ubuntu. Once those are installed we will verify everything by using Socket.IO to build a realtime chat web application.
[ad name=”Google Adsense”]
I’ve placed sudo commands where I needed to on my system, your mileage may vary so feel free to adjust.
With Ubuntu 10.04 up and running go into the terminal and run the following commands (assuming you don’t have Git or OpenSSL installed):
$ sudo apt-get update $ sudo apt-get install git-core $ sudo apt-get install build-essential openssl libssl-dev
You shouldn’t get any errors and you should end up with Git properly installed. Now I’ll use Git to install the latest version of Node.js (and I need SSL for the Socket-IO example to work so I’ve included that, modify this if you don’t need SSL, ex: $ ./configure –without-ssl):
$ git clone https://github.com/joyent/node.git && cd node $ ./configure $ make $ sudo make install
Update Oct. 27, 2010: If you get an error when running ./configure, then go with the (current) stable version of Node instead:
$ git checkout v0.2.4 $ ./configure $ make $ sudo make install
This will take some time to complete. Once everything is finished run the following command to ensure you have Node up and running:
$ node -v
The result should be similar to this:
To install NPM you will need to install curl assuming you don’t already have it installed. By default though on my clean Ubuntu 10.04 Desktop ISO curl wasn’t installed. Here is what you need to do to fix that:
$ sudo apt-get install curl
Now you can grab NPM and install it (I moved out of the node folder first):
curl http://npmjs.org/install.sh | sh
Note: Don’t use sudo for the above command. If you get a permission error you can refer to the NPM site to troubleshoot. I ran this command and it worked for me:
$ sudo chown -R $USER /usr/local
Now it’s time to try out NPM and Node. Lets install Socket.IO.
$ npm install socket.io
Now we can try out the example from the socket.io website. First, let’s grab the latest example source code and pull it down to our computer:
$ git clone git://github.com/LearnBoost/Socket.IO-node.git socket.io-node --recursive && cd socket.io-node/example/
Run the code:
$ sudo node server.js
Note: Running without root privileges is possible but the Flash websocket transport won’t work.
Open up your browser to this address: http://localhost:8080
[ad name=”Google Adsense – large sqr rounded”]