I am Hack Sparrow
Captain of the Internets.

How to install Node.js on Ubuntu Linux

Installing Node.js on Ubuntu


Although there is an official Linux installation documentation, and an unofficial installation script to help you install Node.js on Linux systems, things generally don't go smoothly or reliably. I will show you the core basics of installing Node.js on an Ubuntu system. These instructions will be immensely helpful if it is a Freshly installed Ubuntu system.

First of all make sure you have all the dependencies installed.

$ sudo apt-get -y install build-essential g++ libssl-dev pkg-config

From Node v0.6.3 onward, npm comes bundled with Node. There's no need for installing it separately anymore.

If you don't do that, you are likely to encounter these errors later. In case if you are wondering why we need curl, it is used for installing npm, the Node Package Manager.

$./configure
Checking for program g++ or c++ : not found
Checking for program icpc : not found
Checking for program c++ : not found
... node-v0.6.2/wscript:254: error: could not configure a cxx compiler!
...
$ apt-get install g++
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
...
$./configure
Checking for header openssl/crypto.h : not found
... node-v0.6.2/wscript:366: error: Could not autodetect OpenSSL support. Make sure OpenSSL development packages are installed. Use configure --without-ssl to disable this message.
... Checking for openssl : not found

If you need to install node at a certain location, you can do it this way:

$ ./configure --prefix=$HOME

Once the dependencies are taken care of, we will get the latest source code of Node.js, compile it, and install it. The source code is available at http://nodejs.org/#download, as of this writing it is http://nodejs.org/dist/v0.6.2/node-v0.6.2.tar.gz.

First, let's create a temporary directory where we can download the source code and do the compiling.

$ mkdir /tmp/nodejs

Next, we cd to the temporary directory, get the Node.js source, compile and install it.

$ cd /tmp/nodejs
$ wget http://nodejs.org/dist/v0.6.2/node-v0.6.2.tar.gz
...
$ tar -zxvf node-v0.6.2.tar.gz
...
$ cd node-v0.6.2
$ ./configure
...
$ make
...
$ sudo make install

If you try to install without sudo, you are most likely to run into this error:

Cannot create folder '/usr/local/include/node/' (original error: [Errno 13] Permission denied: '/usr/local/include/node/')

And that's it! You have successfully installed Node.js on your Ubuntu box. Confirm it with:

$ node -v
v0.6.2

Now that you have installed Node.js, it's time to install npm to manage Node packages.

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

Once you have installed npm, confirm it's working. We will check the npm version and install Express (a web development framework in Node.js).

$ npm -v && sudo npm install express -g
1.0.106
/usr/local/bin/express -> /usr/local/lib/node_modules/express/bin/express
express@2.5.1 /usr/local/lib/node_modules/express
├── mime@1.2.4
├── mkdirp@0.0.7
├── qs@0.3.2
└── connect@1.8.0

Congratulations! Welcome to the amazing world of Node.js development!

Any problem with the installation? Ping me in the comments.

14 Responses to “How to install Node.js on Ubuntu Linux”

  1. Frank says:

    …forgot to say, worked perfect with http://nodejs.org/dist/node-v0.6.9.tar.gz. For reference.

  2. Naresh says:

    Dear Captain
    Please mention “where we can install nodejs, npm, express and socket.io”
    For example:
    nodejs installed path: usr/local/

    Thank U

  3. Captain says:

    Naresh, npm is installed by default. You can install express, socket.io and other Node modules in any writable directory. Just cd to the directory and do this:

    npm install socket.io

    It is recommended to install Express as a global module:

    nom install express -g

    Hope that helps.

  4. Arsen says:

    Hello,
    Your instruction is very good. But can you edit link npm, please:

    http://npmjs.org/install.sh to “htts”

    Because it could stop beginners

Make a Comment