您的位置:首页 > 运维架构 > Linux

CentOS 下安装 git + node.js

2012-08-03 09:12 555 查看
首先编译 git 以便可以 clone node.js

最新版git可以在 http://git-scm.com/download 下找到

wget http://kernel.org/pub/software/scm/git/git-1.7.4.1.tar.bz2
tar -xjf git-1.7.4.1.tar.bz2

cd git-1.7.4.1.tar.bz2/

./configure

make

make install

截下来下载并编译 node.js

git clone git://github.com/joyent/node.git

cd node/

./configure

make

make install

As NodeJS v0.4.0 is out, I thought I’d have a play around with it (something I haven’t done in a very long time!)

Instantly I ran into problems:

$ ./configure
Traceback (most recent call last):
File "/Users/greim/nodestuff/node/tools/waf-light", line 157, in     import Scripting
File "/Users/greim/nodestuff/node/tools/wafadmin/Scripting.py", line 146     except Utils.WafError, e:
^
SyntaxError: invalid syntax


I’m trying to install this on my Arch Desktop, which has Python version 3.1.3 installed. After

some
research I found that it was a compatibility issue between Python 2.x and 3.x.

I didn’t really want to remove Python 3 as I’d had
dependency
hell
recently. Inspired by an
answer on StackOverflow, I had a dig about in my /usr/bin directory to see if there was both Python v3
and Python v2 installed. Fortunately there was: /usr/bin/python2

After some trial and error, all I had to do was to edit 2 files:

/tmp/node-v0.4.0/tools/waf-light

amending the first line to read:

#!/usr/bin/env python2


and once I had run ./configure edit the first line in the Makefile to read:

WAF=python2 tools/waf-light


Simple!

Now I have Node JS version 0.4.0 running on my Arch box.

接下来可以试试看 node.js 提供的http server的例子

var http = require('http');

http.createServer(function (req, res) {

res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('Hello World\n');

}).listen(8124, "127.0.0.1");

console.log('Server running at http://127.0.0.1:8124/');
保存为 test.js

然后执行 node test.js
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: