源码安装node8.11.1
源码下载地址:https://nodejs.org/zh-cn/download/
该node版本需要gcc4.9.4以上,这里因为没有找到很好的yum安装地址,所以也用源码安装(这里我用的是5.3.0)
gcc源码地址:http://www.netgull.com/gcc/releases/gcc-5.3.0/
在安装过程中可能需要一些特定的开发工具(包括低版本的gcc,因为gcc编译似乎需要有gcc环境),也可以简单粗暴用一条命令全部安装
yum groupinstall "Development Tools"
1.1 编译安装gcc
tar -zxf gcc-5.3.0.tar.gz cd gcc-5.3.0 ./contrib/download_prerequisites # 下载安装依赖 mkdir /usr/local/gcc5.3.0 cd /usr/local/gcc5.3.0 /root/gcc-5.3.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib make make install
1.2 重建软连接
cd /usr/bin/ mv gcc gcc4.8.6 mv g++ g++4.8.6 ln -s /usr/local/gcc5.3.0/bin/gcc gcc ln -s /usr/local/bin/gcc5.3.0/g++ g++
1.3 验证安装是否成功
gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /root/gcc-5.3.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib Thread model: posix gcc version 5.3.0 (GCC) g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /root/gcc-5.3.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib Thread model: posix gcc version 5.3.0 (GCC)
1.4 更新动态库
find /usr/local/gcc-5.3.0/ -name "libstdc++.so*" cp /usr/local/gcc-5.3.0/stage1-x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.21 /usr/lib64 cd /usr/lib64 rm -rf libstdc++.so.6 ln -s libstdc++.so.6.0.21 libstdc++.so.6
到此,gcc已经安装完成,下面开始编译安装node
2.1 编译安装node8.11.1
cd ~ tar -xvf node-v8.11.1.tar.gz cd node-v8.11.1 ./configure --prefix=/usr/local/node8.11.1 make make install
2.2 增加环境变量
vim /etc/profile 在最下面新增如下内容 #set for nodejs export NODE_HOME=/usr/local/node8.11.1 export PATH=$NODE_HOME/bin:$PATH source /etc/profile
2.3 验证
node -v v8.11.1 npm -v 5.6.0
2.4 安装淘宝cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org 验证 cnpm -v cnpm@5.3.0 (/usr/local/node8.11.1/lib/node_modules/cnpm/lib/parse_argv.js) npm@5.8.0 (/usr/local/node8.11.1/lib/node_modules/cnpm/node_modules/npm/lib/npm.js) node@8.11.1 (/usr/local/node8.11.1/bin/node) npminstall@3.5.0 (/usr/local/node8.11.1/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js) prefix=/usr/local/node8.11.1 linux x64 3.10.0-514.el7.x86_64 registry=https://registry.npm.taobao.org