一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

CentOS系统安装Node.js方法总结

时间:2014-06-19 编辑:简简单单 来源:一聚教程网

准备工作
1、CentOS系统升级Python到2.7.3
2、Python 2.7.3安装bz2扩展

请一定完成以上操作后再执行下面操作,否则请重新来过吧,而且你会遇到下面的错误

 代码如下 复制代码
fpu = 'vfpv3' if armv7 else 'vfpv2'

准备工作做完后,就可以轻松的安装node.js了

 代码如下 复制代码

wget http://nodejs.org/dist/v0.10.26/node-v0.10.26.tar.gz
tar zxvf node-v0.10.26.tar.gz
cd node-v0.10.26
./configure
make
make install

安装nodejs的时候提示以下错误:

ImportError: No module named bz2

解决方法:

 代码如下 复制代码

1.
# yum install -y bzip2*
2.
# cd Python-2.7/Modules/zlib
# ./configure ;make;make install
3.
# cd Python-2.7/
# python2.7 setup.py install

下面来个简单的例子来感受一下node.js的强大功能

 代码如下 复制代码

var http = require('http');
http.createServer(function(req,res){
    res.writeHead(200, {'Content-type': 'text/plain'});
    res.end('Hello World!n');
}).listen(1337,'xx.xx.xx.xx');
console.log('Server running at http://xx.xx.xx.xx:1337');

把xx.xx.xx.xx换成你服务器的ip地址,保存以上内容到example.js,之后运行

 代码如下 复制代码

# node example.js
Server running at http://xx.xx.xx.xx:1337

接下来打开你的浏览器,输入http://xx.xx.xx.xx:1337看看吧!

在这里要注意一下:如果你是centos5.5安装nodejs我们的python版本要在python 2.4否则可能会出错

热门栏目