Dec 14

Hi Folks!

In this tutorial, I will show you how to setup Node JS in Ubuntu 10.04.

Here are the things we would install

  • GNU make 3.81 or newer. Pre-installed on most systems. Sometimes called gmake.
  • Python 2.6 or 2.7. The build tools distributed with Node run on python.
  • libssl-dev (Node v0.6.x only.) Can usually be installed on *NIX systems with your favorite package manager. Pre-installed on OS X.
  • Node JS 

STEP 1:

For gmake, in ubuntu its make, so what you’ll do is:

1
sudo ln -s /usr/bin/make /usr/bin/gmake

STEP 2:

We need to install python 2.7

You can install python via apt-get:

1
2
3
4
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.7

or by compiling python

1
2
3
4
5
6
7
8
sudo apt-get install build-essential
sudo apt-get install libreadline5-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
cd Downloads/
wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz
tar -xvf Python-2.7.2.tgz && cd Python-2.7.2/
./configure
make
sudo make altinstall

Step 3:

1
sudo apt-get install libssl-dev

Step 4:

1
2
3
4
5
6
git clone https://github.com/joyent/node.git
cd node
git checkout v0.6.19 #Try checking nodejs.org for what the stable version is
./configure
make
sudo make install

Then you are done installing Node JS!!!!

Now to test your node js do the hello world test by creating a file named hello_world.js and paste the code below.

1
2
3
4
5
6
7
8
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");

console.log('Hello World!');
console.log('Server running at http://127.0.0.1:8124/');

Then execute the node command in the terminal

1
node hello_node.js

You should see an output like this:

1
2
3
Hello World!

Server running at http://127.0.0.1:8124/

If you are one of the people (Like me) who committed the mistake of installing node js via “sudo apt-get install node” here is how to fix your problem:

1
2
3
4
5
echo $PATH
/usr/local/sbin:/usr/loca<wbr>l/bin:/usr/sbin:/usr/bin:<wbr>/sbin:/bin:/usr/games
</wbr></wbr>

export PATH=$PATH:/usr/bin

sources:

http://ubuntuforums.org/showthread.php?t=389841

http://askubuntu.com/questions/101591/how-do-i-install-python-2-7-2-on-10-04

https://github.com/joyent/node/wiki/Installation

http://www.quora.com/How-do-I-fix-this-error-for-node-js

http://howtonode.org/how-to-install-nodejs

 

Tags: , ,

Categories: Javascript


Leave a Reply