Gangmax Blog

install node.js and npm on Ubuntu 10.04

This article referred the following articles:

Installing node.js on ubuntu 10.04 “Installing node.js on ubuntu 10.04”

isaacs / npm

Installing Node.js and NPM on Ubuntu 10.04 and try a simple chat application

1. Install node.js

First, install the depended packages and get the node.js code from github.

1
2
3
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
git clone git://github.com/joyent/node.git

besides the method above, you can also download the source code package from the “node.js” offical website.

Then make/install the node.js code.

1
2
3
4
cd node
./configure
make # This took about 4 minutes and 25 seconds on my computer.
sudo make install # You can run "sudo make uninstall" to uninstall.

2. Install npm (the node.js package manager)

Note that: if you compile “node.js” with the source code package downloaded from the offical website, then “npm” is ready to use and the following step is not required(at least for v0.8.0 it is, the version on Jun 26, 2012).

Install npm by running the following command:

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

Install some packages to test if npm works:

1
npm install socket.io # This will install the socket.io to your "~/.npm" directory.

Then you can review the install packages by running the following command:

1
2
3
4
5
6
7
8
9
node$ npm ls
/home/user/coderoot/github/node
└─┬ socket.io@0.8.7
├── policyfile@0.0.4
├── redis@0.6.7
└─┬ socket.io-client@0.8.7
├── uglify-js@1.0.6
├── websocket-client@1.0.0
└── xmlhttprequest@1.2.2

3. Run some node.js code snippet to test if it works

1
2
3
4
5
6
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8080/');

Then run the following command to test the program:

1
node server.js

4. Uninstall

Added@20120830

The “uninstall” action requires you have the original source code when you did the installation. If you haven’t, you should download it first.

Then go to the root directory of the extracted source code, run:

1
sudo make uninstall

If you get some error message, such as some file is missing, you need to run “sudo make install” first, to reinstall/overwrite you installed same version “node.js”. Then run the “sudo make uninstall” again to uninstall. At this time it should success without error.

Then you can install the newer version of node.js as above.

Comments