您的位置:首页 > Web前端 > Node.js

node.js在Ubuntu 12.04下的安装和配置

2012-07-19 17:36 771 查看
准备一些包
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: