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
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.
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?
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
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
$ 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
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
/usr/local/bin/express -> /usr/local/lib/node_modules/express/bin/express
Congratulations! Welcome to the amazing world of Node.js development!
Any problem with the installation? Ping me in the comments.