The following describes how to install node. js on Mac, Ubuntu, centos, and Windows respectively.
Mac
On Mac, if you like to use homebrew, you can use only one line to install it:
brew install node
Otherwise, you can only manually install it as follows:
- Install xcode
- Install git
- Run the following command line to compile node. js
1 git clone git://github.com/joyent/node.git
2 cd node
3 ./configure
4 make
5 sudo make install
Ubuntu
- Install dependency packages
1 sudo apt-get install g++ curl libssl-dev apache2-utils
2 sudo apt-get install git-core
- Run the following command line:
1 git clone git://github.com/joyent/node.git
2 cd node
3 ./configure
4 make
5 sudo make install
Windows
To install node with cygwin, follow these steps:
- Install cygwin
- Run setup.exe in the cygwindirectory to install the package in the following list.
- Devel → OpenSSL
- Devel → G ++-gcc
- Devel → make
- Python → Python
- Devel → git
- Run cygwin
- Run the following command line:
1 git clone git://github.com/joyent/node.git
2 cd node
3 ./configure
4 make
5 sudo make install
Centos
1 yum install gcc-c++ openssl-devel
2 wget --no-check-certificate https://github.com/joyent/node/tarball/v0.3.3
3 tar -xzvf ry-node-v0.3.3-0-g57544ba.tar.gz
4 cd ry-node-v0.3.3-0-g57544bac1
5 ./configure
6 make
7 make install
Hello node. JS!
Write a small program such as hello_node.js to verify whether the installation is correct:
1 var http =require('http');
2 http.createServer(function(req, res){
3 res.writeHead(200,{'Content-Type':'text/plain'});
4 res.end('Hello Node.js\n');}).listen(8124,"127.0.0.1");
5 console.log('Server running at http://127.0.0.1:8124/');
Use node to run this code
1 node hello_node.js
2 Server running at http://127.0.0.1:8124/
Now, open http: // 127.0.0.1: 8124/in a browser, and you should be able to see good news.