linux下的安装命令如下所示:wget http://nodejs.org/dist/v0.10.5/node-v0.10.5.tar.gz tar zxvf node-v0.10.5.tar.gz cd node-v0.10.5.tar.gz ./configure --prefix=/home/zhaolincheung/local/nodejs make && make intall注:这里将node.js安装在/home/zhaolincheung/local/nodejs目录下。node.js的安装需要python2.6以上的支持,否则在执行./configure时会出错;node.js还需要gcc-c++的支持,所以系统需要实现安装gcc-c++。通过 node -v来检查安装是否成功,如果返回:v.0.10.5,则说明安装成功。至此node.js已经编译并安装完成。如需卸载,可以执行make uninstall进行卸载。
三.简单的hello world程序
学习任何语言或者框架,首先要写的程序就是hello world程序。这里也是这样,我们来写一个简单的hello world程序。首先,编写helloworld.js,内容如下:var http = require("http");http.createServer(function(req, res) { res.writeHead(200, {"Content-Type":"text/plain"}); res.end("Hello World
"); }).listen(10001);console.log("Server running at http://127.0.0.1:10001/");其次,执行该文件:/home/zhaolincheung/local/nodejs/bin/node helloworld.js 最后,通过浏览器访问http://127.0.0.1:1337便得到了hello world的响应。