解决node: /lib64/libm.so.6: version `GLIBC_2.27‘ not found (required by node)

node运行的时候报了以下几个错误,查阅了不少资料,原因主要是与系统中安装的 glibc 和 libstdc++ 版本过低有关,导致无法满足 Node.js 运行所需的库版本要求。折腾半天成功解决,这里记录一下我的处理过程

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)

解决办法:更新glibc和libstdc++

1、更新glibc

wget https://ftp.gnu.org/gnu/glibc/glibc-2.30.tar.gz
tar xf glibc-2.30.tar.gz 
cd glibc-2.30
mkdir build
cd build/
../configure --prefix=/usr --disable-profile --enable-add-ons --with-binutils=/usr/bin

出现如下报错

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

安装bison、升级gcc、make

安装bison

yum -y install bison
bison --version
bison (GNU Bison) 3.0.4
Written by Robert Corbett and Richard Stallman.

Copyright (C) 2015 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.

升级gcc

##查看现有版本
gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 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.

下载gcc源码包
https://mirror.marwan.ma/gcc/releases/gcc-12.1.0/gcc-12.1.0.tar.gz
tar xf gcc-12.1.0.tar.gz -C /usr/local/

##查看gcc需要的依赖
vim  /usr/local/gcc-12.1.0/contrib/download_prerequisites

 下面4个包就是gcc需要的依赖

##下载依赖
wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2
wgte https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz
wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2

##解压
tar xf gmp-6.2.1.tar.bz2 -C /usr/local/gcc-12.1.0/
tar xf mpfr-4.1.0.tar.bz2 -C /usr/local/gcc-12.1.0/
tar xf mpc-1.2.1.tar.gz -C /usr/local/gcc-12.1.0/
tar xf isl-0.24.tar.bz2 -C /usr/local/gcc-12.1.0/

##建立软连接
cd /usr/local/gcc-12.1.0/
ln -sf gmp-6.2.1 gmp
ln -sf mpfr-4.1.0 mpfr
ln -sf mpc-1.2.1 mpc
ln -sf isl-0.24 isl

编译安装gcc

cd /usr/local/gcc-12.1.0/
mkdir build
cd build
../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib

##这里时间较长,我的是80核的,用了差不多90分钟
make -j80 && make install

##完成之后建立软连接
mv /usr/bin/gcc /usr/local/gcc.bak
ln -s /usr/local/bin/gcc /usr/bin/gcc

 查看升级后的gcc

gcc --version
gcc (GCC) 12.1.0
Copyright (C) 2022 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.

接下来继续升级make

##查看现有版本
make --version
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar xf 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 -s /usr/local/make/bin/make /usr/bin/make

查看升级后的make版本

make --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

继续更新glibc

cd glibc-2.28/build/
../configure --prefix=/usr --disable-profile --enable-add-ons --with-binutils=/usr/bin

make && make install

继续报错,如下

../sysdeps/nptl/pthread.h:744:47: error: argument 1 of type ‘struct __jmp_buf_tag *’ declared as a pointer [-Werror=array-parameter=]
  744 | extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL;
      |                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from ../include/setjmp.h:2,
                 from ../nptl/descr.h:24:
../setjmp/setjmp.h:54:46: note: previously declared as an array ‘struct __jmp_buf_tag[1]’
   54 | extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
      |                         ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [../Makerules:287: /root/glibc-2.28/build/tcb-offsets.h] Error 1
make[2]: Leaving directory '/root/glibc-2.28/csu'
make[1]: *** [Makefile:258: csu/subdir_lib] Error 2
make[1]: Leaving directory '/root/glibc-2.28'
make: *** [Makefile:9: all] Error 2

解决办法

##清楚之前的构建文件
make distclean

##添加CFLAGS="-Wno-error"
CFLAGS="-Wno-error" ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

make && make install

然后还是提示错误

In file included from <command-line>:
./../include/libc-symbols.h:75:3: error: #error "glibc cannot be compiled without optimization"
   75 | # error "glibc cannot be compiled without optimization"
      |   ^~~~~
In file included from ../include/pthread.h:1,
                 from ../nptl/../nptl_db/thread_db.h:25,
                 from ../nptl/descr.h:32,
                 from ../sysdeps/x86_64/nptl/tls.h:130,
                 from ../sysdeps/unix/sysv/linux/x86_64/sysdep.h:24,
                 from <stdin>:1:
../sysdeps/nptl/pthread.h:744:47: warning: argument 1 of type ‘struct __jmp_buf_tag *’ declared as a pointer [-Warray-parameter=]
  744 | extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __THROWNL;
      |                         ~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from ../include/setjmp.h:2,
                 from ../nptl/descr.h:24:
../setjmp/setjmp.h:54:46: note: previously declared as an array ‘struct __jmp_buf_tag[1]’
   54 | extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
      |                         ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
make[2]: *** [../Makerules:287: /root/glibc-2.28/build/tcb-offsets.h] Error 1
make[2]: Leaving directory '/root/glibc-2.28/csu'
make[1]: *** [Makefile:258: csu/subdir_lib] Error 2
make[1]: Leaving directory '/root/glibc-2.28'
make: *** [Makefile:9: all] Error 2

添加 -O2 解决优化问题优化

make distclean
CFLAGS="-Wno-error -O2" ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
make && make install

使用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++

##查看系统版本

strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
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
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_DEBUG_MESSAGE_LENGTH


strings /usr/lib64/libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_TM_1

ls -l /usr/lib64/libstdc*
lrwxrwxrwx. 1 root root       19 Feb 16 15:52 /usr/lib64/libstdc++.so.6 -> libstdc++.so.6.0.19
-rwxr-xr-x. 1 root root   995840 Sep 30  2020 /usr/lib64/libstdc++.so.6.0.19

目前用的是6.0.19,没有CXXABI_1.3.9、GLIBCXX_3.4.20、GLIBCXX_3.4.21

进入前面编译gcc的输入目录

cd /usr/local/gcc-12.1.0/build/

 查找编译生成libstdc++.so库文件

find ./ -name libstdc++.so*

##拷贝libstdc++.so.6.0.30库文件到lib64目录
cp ./x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.30 /usr/lib64/

创建软链接

cd /usr/lib64/

##删除原来的文件
rm -rf libstdc++.so.6

##软连接
ln -s libstdc++.so.6.0.30 libstdc++.so.6

ll libstdc*
lrwxrwxrwx. 1 root root       19 Feb 16 15:52 libstdc++.so.6 -> libstdc++.so.6.0.30
-rwxr-xr-x. 1 root root   995840 Sep 30  2020 libstdc++.so.6.0.19
-rwxr-xr-x. 1 root root 14981728 Feb 16 15:51 libstdc++.so.6.0.30

再次使用node,搞定

node -v
v18.20.6
### CentOS 镜像中 README 文件的作用 README 文件通常作为文档的一部分,在操作系统或软件包的分发过程中起到指导和说明的作用。对于 CentOS 的镜像而言,其 README 文件的主要意义在于提供关于该版本的操作系统的关键信息以及安装指南。 #### 1. 提供版本信息 README 文件会明确指出当前镜像是哪个具体版本的 CentOS,例如 `CentOS Linux release 7.9.2009 (Core)`[^1]。这有助于用户确认所下载的是正确的发行版,并了解与其兼容的硬件和软件环境。 #### 2. 描述安装前准备事项 在实际部署之前,用户可能需要完成一些必要的准备工作,比如安装工具 Git 或者其他依赖项。这些内容往往会在 README 中有所提及,帮助新手快速上手。 #### 3. 解决常见问题 针对可能出现的问题,如文件上传验证通过后的反馈机制——返回文件名表示成功[^2];或者如何正确配置服务端口映射等复杂场景下的解决方案也可能被记录下来以便查阅。 #### 4. 列举第三方库源地址 有时为了扩展功能,官方文档还会给出获取额外资源的方法论实例:“`wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz`” 就是用来示范怎样从外部站点拉取所需组件的例子之一[^3]。 #### 5. 展示高级设置教程 除了基本操作外,更深入的技术细节也会包含其中,例如为了让 NVM 成为全局变量而修改特定路径下的脚本文件 `/etc/profile.d/nvm.sh` [^4] ,或者是利用 FTP 协议传输大容量数据时推荐采用 Binary Mode 来保持文件完整性[^5]。 综上所述,README 不仅是一个简单的介绍性文本,更是连接开发者与最终用户的桥梁,它承载着丰富的背景资料和技术支持,使得整个安装过程更加顺畅高效。 ```bash # 示例命令展示如何查看本地是否存在类似的 readme 文档 ls /path/to/your/downloaded/image/*.txt | grep -i "readme" cat /path/to/found/readme.txt ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值