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

centos 6.x x86_64装nodejs模块ws

2015-11-04 00:00 706 查看
摘要: 为了在nodejs下用下websocket,需要装个ws模块,于是就去装了。我知道还有其他模块实现,反正我就选了这个去实验。

为了在nodejs下用下websocket,需要装个ws模块,于是就去装了。我知道还有其他模块实现,反正我就选了这个去实验。

关于centos装nodejs请参考这文章:http://stackoverflow.com/questions/20028996/how-to-install-node-binary-distribution-files-on-linux ,用的是Amin Meyghani的回复方法。

一开始当然是不成功的,发现有个关键提示:

../node_modules/nan/nan.h:41:3: error: #error This version of node/NAN/v8 requires a C++11 compiler

搜索了下发现C++11需要gcc 4.7以上,系统默认的是4.4.7.不合要求。

下面正确装ws模块的节奏:

step 0:

升级 gcc 到4.7以上,参考:http://superuser.com/questions/381160/how-to-install-gcc-4-7-x-4-8-x-on-centos

不过我装的是devtools-2,一个不新不旧的版本。

cd /etc/yum.repos.d
wget http://people.centos.org/tru/devtools-2/devtools-2.repo yum --enablerepo=testing-2-devtools-6 install devtoolset-2-gcc devtoolset-2-gcc-c++

2.0的安装好位置在:

/opt/rh/devtoolset-2/root/usr/bin/

注意不是1.1的:

/opt/centos/devtoolset-1.1/root/usr/bin/

相应export环境变量也改成:

export CC=/opt/rh/devtoolset-2/root/usr/bin/gcc
export CPP=/opt/rh/devtoolset-2/root/usr/bin/cpp
export CXX=/opt/rh/devtoolset-2/root/usr/bin/c++

gcc升级完成。这时运行gcc -v仍旧显示 4.4.7,应该是path没改,但这样也不影响node-gyp编译,就没理会它。

step 1:

装ws模块

npm install -g ws

ws模块编译通过,安装成功。

Done,可以愉快的使用ws了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nodejs centos websocket