下面分别介绍在Mac, Ubuntu,Centos以及Windows下安装Node.js.
Mac
在Mac下,如果你喜欢用homebrew,那么只用一行就可以装好:
brew install node
否则,只能考虑手工安装了,步骤如下:
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make installUbuntu
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-coregit clone git://github.com/ry/node.git
cd node
./configure
make
sudo make installWindows
用cygwin来安装node,步骤如下:
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make installCentos
yum install gcc-c++ openssl-devel
wget --no-check-certificate https://github.com/ry/node/tarball/v0.3.3
tar -xzvf ry-node-v0.3.3-0-g57544ba.tar.gz
cd ry-node-v0.3.3-0-g57544bac1
./configure
make
make install
Hello Node.js!
写一段小程序例如hello_node.js来验证安装是否正确:
var http = require(\'http\');
http.createServer(function (req, res) {
res.writeHead(200, {\'Content-Type\': \'text/plain\'});
res.end(\'Hello Node.jsn\');
}).listen(8124, "127.0.0.1");
console.log(\'Server running at http://127.0.0.1:8124/\');
用node来运行这段代码
node hello_node.js
Server running at http://127.0.0.1:8124/
现在,用浏览器打开 http://127.0.0.1:8124/ , 应该能够看到一条好消息。