GLIBC_2.28 not found CentOS7不兼容Node高版本(18以上)

CentOS7中默认不支持高版本nodejs(18以上)

报错如下

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)

切换到root权限

su // 回车后。输入root密码

升级GCC(默认为4,升级为7。尝试了几次升级为8.3后系统崩了,心态也崩了)

yum install -y centos-release-scl
yum install devtoolset-7-gcc devtoolset-7-gcc-c++ // yum install -y devtoolset-7-gcc*
mv /usr/bin/gcc /usr/bin/gcc-4.8.5 // 原始版本保留
ln -s /opt/rh/devtoolset-7/root/bin/gcc /usr/bin/gcc // 引用新版本
mv /usr/bin/g++ /usr/bin/g++-4.8.5 // // 原始版本保留
<!-- configure: error: no acceptable C compiler found in $PATH或者无法获取"/usr/bin/g++" 的文件状态(stat): 没有那个文件或目录
执行 yum install gcc-c++  //使用yum install gcc-c++时会自动安装/升级gcc及其他依赖的包
-->
ln -s /opt/rh/devtoolset-7/root/bin/g++ /usr/bin/g++ // 引用新版本

升级 make(默认为3 升级为4)

wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar -xzf make-4.3.tar.gz && cd make-4.3/
./configure  --prefix=/usr/local/make
make -j 4 && make install  // 加快编译速度(建议不要超过CPU核心数量)(如果没有make命令需要安装一下make命令  yum install -y make)
cd /usr/bin/ && mv make make.bak
ln -sv /usr/local/make/bin/make /usr/bin/make

更新libstdc++.so.6.0.26

wget https://cdn.frostbelt.cn/software/libstdc%2B%2B.so.6.0.26 // 更新lib  libstdc++.so.6.0.26
cp libstdc++.so.6.0.26 /usr/lib64/ // 替换系统中的/usr/lib64
cd /usr/lib64/
ln -snf ./libstdc++.so.6.0.26 libstdc++.so.6

更新glibc

wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar xf 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
<!-- 可能报错
*** These critical programs are missing or too old: make bison compiler
*** Check the INSTALL file for required versions. 
执行 yum install -y bison
-->
make -j 4 && make install  // 记住先备份,此步比较长
<!-- 系统变成了英文。glibc/budil目录下执行
make localedata/install-locales
-->

验证

npm -v
node -v
posted @ 2024-05-20 10:00  萝卜爱吃肉  阅读(342)  评论(0编辑  收藏  举报