解决 centos使用node 报错 version 'GLIBC_2.27' not found

解决 centos使用node 报错 version ‘GLIBC_2.27’ not found…

完整报错

node -v
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)

报错原因

网上查了一下貌似是因为centos现在不维护了。导致安装最小的node之后,系统里这些东西版本太低不支持。

先查看系统内的glibc版本

strings /lib64/libc.so.6 |grep GLIBC_

上面命令执行完,会发现GLIBC版本缺少报错里所需的几个版本

安装glibc

## 编译安装glibc
cd /root
## 下载tar包
wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
## 解压tar包
tar xf glibc-2.28.tar.gz
## 删除安装包
rm glibc-2.28.tar.gz
## 编译
cd glibc-2.28/ && mkdir build && cd build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

注意这里可能在最后输出报错,如果报错则下一步,没报错的话继续执行

## 安装glibc
make && make install

处理glibc编译报错

如果上一步编译没有报错,略过,直接下一步

上一步的最后可能会报错

# configure: error: 
# *** These critical programs are missing or too old: compiler
# *** Check the INSTALL file for required versions.

如果报错了,则需要升级gcc和make

## 安装GCC
yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
## 设置环境变量
echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile
source /etc/profile

## 升级 make
wget https://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar -xzvf make-4.3.tar.gz
rm make-4.3.tar.gz
cd make-4.3/
./configure --prefix=/usr/local/make
make && make install
## 创建软链接
cd /usr/bin/ && mv make make.bak
ln -sv /usr/local/make/bin/make /usr/bin/make

## 重新编译上一步的glibc
cd /root/glibc-2.28/build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
## 安装glibc
make && make install

验证glibc版本

此时再查看一下glibc版本

strings /lib64/libc.so.6 |grep GLIBC_

会发现所需版本已经安装好了。继续执行node -v发现依然会报错,但少了两个

node -v
# node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
# node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
# node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)

更新libstdc

## 安装libstdc
yum install libstdc++.so.6 -y
## 查看CXXABI版本
strings /usr/lib/libstdc++.so.6 | grep 'CXXABI'
## 下载需要的libstdc版本
wget https://cdn.frostbelt.cn/software/libstdc%2B%2B.so.6.0.26
# 更新软连接
cp libstdc++.so.6.0.26 /usr/lib64/
cd /usr/lib64
ln -snf ./libstdc++.so.6.0.26 libstdc++.so.6

验证

node -v
18.17.1

ok~~