This blog post exclusively deals with installing node.js from binaries on Ubuntu. First you need to download the tar ball from node.js website.
Say if the downloaded file(example: node-v0.8.20.tar.gz) is in the Download folder, you need to copy it to /usr/local/src. Fire up the terminal and type in the commands.

sudo cp /home/username/Downloads/node-v0.8.20.tar.gz  /usr/local/src

Now change the directory

cd /usr/local/src

Extract the tar ball

sudo tar -xzvf node-v0.8.20.tar.gz

Change the directory to the extracted folder

cd node-v0.8.20

The configure script checks your system to see if the required dependencies are present.

sudo ./configure

Compile the source files using the following command

sudo make

I have encountered the following error during make.

make[1]: g++: Command not found

You can solve this by installing the build essentials,this package contains an informational list of packages which are considered essential for building Debian packages. here is the command.

apt-get install build-essential

Once you have installed the build essentials, run the make command again. This time hopefully there should be no errors. After make runs successfully install node using the folllowing command

sudo make install

Now get ready for the customary Hello World program.

Fire up a text editor and paste the following contents, save it as hello.js

// Load the http module to create an http server.
var http = require('http');
 
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});
 
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
 
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

If you have saved the hello.js on the desktop, open the terminal navigate to the Desktop folder, then issue the following command

[user]@[system]:~/Desktop$ node hello.js

Open a browser and navigate to the following address:

http://127.0.0.1:8000/
You should see Hello World message.

Congratulations on successfully installing node.js and testing the setup.

  1. FYI, this is not installing from binaries, but from source. The title is confusing because there is actually a pre-compiled tarball containing binaries available from node.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>