操作系统为centos6.10,在安装nodejs最新版本的时候报错,依赖glibc的高版本和gcc高版本,还要安装python2.7,操作系统上已经跑了很多应用,升级gcc风险过大,采用相对保守的方法:
安装npm并安装n,然后通过n这个工具安装低版本node(比默认yum安装的版本要高)
root@server1 [/home/yt_opsadmin/node-v12.13.0-linux-x64]# bin/node -v
bin/node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by bin/node)
bin/node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.18' not found (required by bin/node)
bin/node: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.5' not found (required by bin/node)
bin/node: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by bin/node)
bin/node: /lib64/libc.so.6: version `GLIBC_2.16' not found (required by bin/node)
bin/node: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by bin/node)
bin/node: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by bin/node)
1.安装epel的yum源
# yum install -y epel-release
2.安装低版本的nodejs和npm
yum install nodejs npm -y
root@server1 [//home/mindmaster0807]# npm --version
1.3.6
root@server1 [//home/mindmaster0807]# node --version
v0.10.48
3.安装n这个管理nodejs的工具
# 需要关闭ssl否则会报错
npm config set strict-ssl false
npm install -g n
# 使用n 这个工具安装node8.2.1版本
n 8.2.1
# 默认版本
root@server1 [/home/yt_opsadmin]# node -v
v0.10.48
# 查看n管理下的所有node版本
root@server1 [/home/mindmaster0807/_coopSocket]# n ls
node/8.2.1
# 查看8.2.1版本所在安装目录
root@server1 [/home/mindmaster0807/_coopSocket]# n which 8.2.1
/usr/local/n/versions/node/8.2.1/bin/node
# 使用软链和替换默认node版本为新版本
root@server1 [/home/yt_opsadmin]# mv /usr/bin/node /usr/bin/node.old
root@server1 [/home/yt_opsadmin]# mv /usr/local/bin/node /usr/local/bin/node.old
root@server1 [/home/yt_opsadmin]# cp /usr/local/n/versions/node/8.2.1/bin/node /usr/bin
root@server1 [/home/yt_opsadmin]# cp /usr/local/n/versions/node/8.2.1/bin/node /usr/local/bin/
root@server1 [/home/yt_opsadmin]# node -v
v8.2.1
# 替换 npm 为新版本
root@server1 [/home/yt_opsadmin]# npm -v
1.3.6
root@server1 [/home/yt_opsadmin]# mv /usr/bin/npm /usr/bin/npm.old
root@server1 [/home/yt_opsadmin]# mv /usr/local/bin/npm /usr/local/bin/npm.old
root@server1 [/home/yt_opsadmin]# ln -s /usr/local/n/versions/node/8.2.1/bin/npm /usr/bin/npm
root@server1 [/home/yt_opsadmin]# ln -s /usr/local/n/versions/node/8.2.1/bin/npm /usr/local/bin/npm
root@server1 [/home/yt_opsadmin]# /usr/local/n/versions/node/8.2.1/bin/npm -v
5.3.0
升级glibc到2.17
1.原先的系统glibc库的版本是2.12,需要升级到2.17版本
root@server1 [/home/yt_opsadmin/node-v12.13.0-linux-x64]# strings /lib64/libc.so.6 | grep GLIBC
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_PRIVATE
wget http://ftp.gnu.org/gnu/glibc/glibc-2.17.tar.gz
2.编译
# 编译时间较长,开启screen避免编译中断
# screen -S glibc
# tar -xf glibc-2.17.tar.gz
# cd glibc-2.17
# mkdir build
# cd build
# 预编译
# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
# 多线程编译,加快编译速度
# make -j 4
# make install
[root@:~]# strings /lib64/libc.so.6 | grep GLIBC
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
GLIBC_PRIVATE
[root@spyzie-DB1:~]# ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.