准備一些包
sudo apt-get install g++ curl libssl-dev apache2-utils
git是不可少的
sudo apt-get install git-core
用git下載node.js最新版
git clone git://github.com/ry/node.git
或者直接下載源碼
wget http://nodejs.org/dist/node-v0.8.2.tar.gz
gunzip node-v0.8.2.tar.gz
tar -xf node-v0.8.2
開始編譯安裝node.js
cd node-v0.8.2
./configure
make
sudo make install
輸入node –v 或者node –version可以查看node.js當前的版本
運行第一個node.js的程序
在主文件夾中創建example.js,編輯文本
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
在命令行中
Node example.js
瀏覽器中瀏覽,瀏覽器中出現hello node.js
