node: /lib64/libm.so.6: version `GLIBC_2.27′ not found _解决方案

背景

刚买了一台服务器,安装操作系统是CentOS-7.6.1810-x64

需要安装node.Js环境,于是就去官网找到了对应版本的下载地址

然后去使用wget命令将其压缩包下载到服务器,进行解压缩

具体操作看下面!

安装node.js

1. 用命令行形式进行下载:

wget https://nodejs.org/dist/v18.16.0/node-v18.16.0-linux-x64.tar.xz

2.解压缩

tar -xvf node-v18.16.0-linux-x64.tar.xz
mkdir -p /usr/local/nodejs
mv node-v18.16.0-linux-x64/* /usr/local/nodejs/

 

 

3.创建软连接

# 建立node软链接
ln -s /usr/local/nodejs/bin/node /usr/local/bin
# 建立npm 软链接
ln -s /usr/local/nodejs/bin/npm /usr/local/bin

 

 

4.验证安装是否成功

node -v
npm -v

 

安装异常

 

结果发现报错了:

[root@172 ~]# npm -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)

 

问题原因

查看系统内安装的glibc版本:

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

然后根据分析可得知 新版的node v18开始 都需要GLIBC_2.27支持,可是目前系统内却没有那么高的版本。

 

解决办法

更新glibc

根据提示 安装所需要的glibc-2.28:

cd /root
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

 

 

执行如上结果发现报错:

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

 

 

解决办法:升级gcc与make

# 升级GCC(默认为4 升级为8)
yum install -y centos-release-scl
yum install -y devtoolset-8-gcc*
mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++

# 升级 make(默认为3 升级为4)
wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar -xzvf 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

 

 

依旧报错:bison太老旧

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

 

 

通过查看bison版本发现是并没有安装...于是直接安装

yum install -y bison

 

 

这时 所有的问题 都已经解决完毕 再重新执行上一步 更新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在linux中就是安装软件的意思 简单这么理解就好。
这个过程较长,大约半小时左右

make && make install

 

再出问题

经过漫长的等待后,怀着激动的信息进行输入node -v 命令:

[root@ecseAyh build]# 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)
[root@ecseAyh build]# npm -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)
[root@ecseAyh build]# 

 

 

我尼玛.....

原因:gcc动态库版本过老

解决:

 

 

a. 查看动态库

[root@ecseAyh build]# strings /usr/lib64/libstdc++.so.6 | grep GLIBC 
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.4
GLIBC_2.3.2
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH
[root@ecseAyh build]# 

 

 

发现最高只有 GLIBCXX_3.4.13,所以这里需要下载最新gcc库:

wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-8.3.0/gcc-8.3.0.tar.gz

 

更多版本:http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/

然后解压:

tar -zxvf gcc-8.3.0.tar.gz

然后编译安装 gcc

cd gcc-8.3.0/ 

./contrib/download_prerequisites

mkdir build

cd build   

../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

 

这是一个漫长的过程

make && make install

cp /usr/local/lib64/libstdc++.so.6.0.25 /usr/lib64

cd /usr/lib64

rm -rf libstdc++.so.6

ln -s libstdc++.so.6.0.25 libstdc++.so.6

 

 

cc1plus: warning: -Wabi won't warn about anything [-Wabi]
cc1plus: note: -Wabi warns about differences from the most up-to-date ABI, which is also used by default
cc1plus: note: use e.g. -Wabi=11 to warn about changes from GCC 7

 

然后再次执行以下命令来查看是否包括 GLIBCXX_3.4.21

strings /usr/lib64/libstdc++.so.6 | grep GLIBC

现在,动态库的版本已经到了GLIBCXX_3.4.25

 

安装完成

node -v

 

微信盖关注

编程那点事儿

编程那点事儿

 

阅读剩余
THE END