参考:
http://www.cnblogs.com/smallidea/archive/2012/07/19/2599734.html
安装依赖包:
sudo apt-get install g++ curl libssl-dev apache2-utils
git下载源码(如果可以git,网络通的,我就很烦躁的代理把git屏蔽了)
sudo apt-get install git-core
git clone git://github.com/ry/node.git
或者离线下载源码
wget http://nodejs.org/dist/node-latest.tar.gz
gunzip node-latest.tar.gz
tar -xf node-latest.tar
(可以访问这里去选择需要下载的版本,以上是下载最新版本)
编译安装node.js
cd node-v0.10.2/
./configure
make
sudo make install
(我解压后的目录是node-v0.10.2,这个要根据实际情况而定)
查看版本命令
node -v
node -version
运行第一个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(8888
);
console.log(
'Server running at http://localhost:8888/'
);
在命令行中
node example.js
浏览器中浏览http://localhost:8888/,浏览器中出现hello node.js
祝贺你安装成功了!!!