Installing Nodejs, NPM and Google V8 on UBUNTU

A) Install the essential compilers, packages and Google V8
sudo apt-get update
sudo apt-get install build-essential curl openssl libv8-2.0.3
B) Download and install the Nodejs from source
wget http://nodejs.org/dist/node-v0.4.11.tar.gz
gunzip node-v0.4.11.tar.gz
tar -xf node-v0.4.11.tar

cd  node-v0.4.11
./configure
make
make install
C) Installing the NPM
curl http://npmjs.org/install.sh | sh
Here is the lazy script to get things installed smoothly in your UBUNTU machine.
#!bin/sh
# Installing Nodejs, NPM and Google V8 on UBUNTU
# Save the code to a file as *.sh
# You should need the google V8

# Update version information here.
NODEJS=node-v0.4.11

TEMP_SOURCEDIR=${HOME}/temp_source

echo "Updating the packages list"
apt-get update
apt-get install build-essential curl openssl libv8-2.0.3
echo "Essential packages are installed"

# Pre-prep cleanup
if [ -d ${TEMP_SOURCEDIR} ]; then
    rm -rf ${TEMP_SOURCEDIR}
fi

mkdir ${TEMP_SOURCEDIR}
cd ${TEMP_SOURCEDIR}/

# Download and install the Nodejs from source
echo "Downloading the Nodejs"
wget http://nodejs.org/dist/${NODEJS}.tar.gz
gunzip ${NODEJS}.tar.gz
tar -xf ${NODEJS}.tar

echo "Installing Nodejs"
cd ${TEMP_SOURCEDIR}/${NODEJS}
./configure
# make clean
make
make install
echo "Done"

# Installing the NPM
echo "Installing NPM"
curl http://npmjs.org/install.sh | sh

# Cleanup
rm -rf ${TEMP_SOURCEDIR}
and
chmod +x install.sh
sudo sh install.sh
#Or
sudo ./install.sh
To test the installation make a JS file (i.e test.js) using the bellow code
var sys = require('sys'),
   http = require('http');
http.createServer(function (req, res) {
  setTimeout(function () {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write('<br/><strong>&nbsp;&nbsp;&nbsp;&nbsp;Hello World!</strong>');
    res.end();
  }, 2000);
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');
Then run it as
node test.js
Reference to Giant Flying Saucer Giant Flying Saucer - http://www.giantflyingsaucer.com/blog/?p=894
Done.
Share this