This article referred the following articles:
Installing node.js on ubuntu 10.04 “Installing node.js on ubuntu 10.04”
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 | sudo apt-get install g++ curl libssl-dev apache2-utils |
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 | cd node |
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 | node$ npm ls |
3. Run some node.js code snippet to test if it works
1 | var http = require('http'); |
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.