阿里云Linux服务器升级glibc到2.28


前言

在使用阿里云的Linux服务器(Alibaba Cloud Linux 2.1903 LTS 64位)时,按照教程安装的是nodejs的V14版本。如果升级了npm到最新的版本,之后使用npm时会提示

ERROR: npm v10.2.4 is known not to run on Node.js v14.0.0.  This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.

那么需要升级nodejs,在升级了nodejs到v21版本后,会提示

[root@iZ2vcim9enkbf26jy2jyinZ ~]# 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_2.28


一、查看当前版本

[root@iZ2vcim9enkbf26jy2jyinZ ~]# 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.

当前版本为2.17

二、更新glibc

1.下载glibc-2.28

//下载
wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
//解压
tar xf glibc-2.28.tar.gz 
//创建并进入build目录
cd glibc-2.28/ && mkdir build  && cd build
//设置编译参数
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

在设置了编译参数之后,可能会出现以下的错误,需要升级gcc与make

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

2.升级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++

这里安装centos-release-scl时可能会出现No package centos-release-scl available,用这两条命令,之后再次安装。

rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl-rh/2/3.el7.centos/noarch/centos-release-scl-rh-2-3.el7.centos.noarch.rpm
rpm -ivh https://cbs.centos.org/kojifiles/packages/centos-release-scl/2/3.el7.centos/noarch/centos-release-scl-2-3.el7.centos.noarch.rpm

安装后,查看gcc的版本为8.3.1

[root@iZ2vcim9enkbf26jy2jyinZ ~]# gcc --version
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
Copyright (C) 2018 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.

3. 升级 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

查看make的版本,为4.3

[root@iZ2vcim9enkbf26jy2jyinZ ~]# 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.

4.再次安装glibc-2.28

接1中,在build目录下再次设置编译参数,没有报错后,执行make && make install

//设置编译参数
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
//编译
make && make install

可能会有以下报错,对应解决后,删除build下的内容,重新编译。
1)报错/usr/bin/ld: cannot find -lnss_test2

#修改glibc-2.28的test-installation.pl文件大概128行
vim '相对目录'/glibc-2.28/scripts/test-installation.pl
    #将 && $name ne "nss_test1" && $name ne "libgcc_s" 
    #改为:
    && $name ne "nss_test1" && $name ne "libgcc_s" && $name ne "nss_test2"

2)undefined reference to ‘_nsl_default_nss@GLIBC_PRIVATE’
在编译选项中加上 --enable-obsolete-nsl,删除build下的内容,再次编译

../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --enable-obsolete-nsl

之后如果成功编译安装了,查看glibc版本,为2.28

[root@iZ2vcim9enkbf26jy2jyinZ ~]# ldd --version
ldd (GNU libc) 2.28
Copyright (C) 2018 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.

5.处理GLIBCXX_3.4.21’ not found

glibc2.28已经安装好了,但是运行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)

处理方式参考解决nvm升级node v18.14.0时/lib64/libm.so.6: version ‘GLIBC_2.27’ not found (required by node)问题

yum whatprovides libstdc++.so.6
yum update -y libstdc++.x86_64

sudo wget http://www.vuln.cn/wp-content/uploads/2019/08/libstdc.so_.6.0.26.zip
unzip libstdc.so_.6.0.26.zip
cp libstdc++.so.6.0.26 /lib64/
cd /lib64

# 把原来的命令做备份
cp libstdc++.so.6 libstdc++.so.6.bak
rm -f libstdc++.so.6

# 重新链接
ln -s libstdc++.so.6.0.26 libstdc++.so.6

之后node -v能够正确执行

[root@iZ2vcim9enkbf26jy2jyinZ ~]# node -v
v21.0.0

参考文章

1、解决nvm升级node v18.14.0时/lib64/libm.so.6: version ‘GLIBC_2.27’ not found (required by node)问题
2、MySQL8(glibc2.28)二进制安装
3、centos7 update glibc to 2.27

  • 38
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Linux 中安装 GLIBC_2.28 版本,您可以按照以下步骤操作: 1. 检查系统中是否已安装 GLIBC 2.28:您可以使用以下命令检查系统中是否已安装 GLIBC 2.28: ``` ls /lib/x86_64-linux-gnu/libc-2.28.so ``` 如果命令输出了文件路径,则表示已经安装了 GLIBC 2.28 版本。如果命令没有输出任何内容,则需要安装 GLIBC 2.28 版本。 2. 下载 GLIBC 2.28 版本的源代码:您可以从 GLIBC 的官方网站上下载 GLIBC 2.28 版本的源代码。下载链接为:https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz 3. 解压源代码包:您可以使用以下命令将源代码包解压到当前目录: ``` tar -zxvf glibc-2.28.tar.gz ``` 4. 在源代码目录中创建一个 build 子目录:您可以使用以下命令在源代码目录中创建一个名为 build 的子目录: ``` mkdir build cd build ``` 5. 配置源代码:您可以使用以下命令配置源代码: ``` ../configure --prefix=/usr/local/glibc-2.28 ``` 这将在 /usr/local/glibc-2.28 目录下安装 GLIBC 2.28 版本。如果您希望将其安装到其他目录,请相应地更改 --prefix 选项的值。 6. 编译源代码:您可以使用以下命令编译源代码: ``` make ``` 7. 安装 GLIBC 2.28 版本:您可以使用以下命令安装 GLIBC 2.28 版本: ``` sudo make install ``` 8. 更新动态链接器缓存:您可以使用以下命令更新动态链接器缓存: ``` sudo ldconfig ``` 安装完成后,您可以使用以下命令检查 GLIBC 的版本: ``` strings /lib/x86_64-linux-gnu/libc.so.6 | grep GLIBC_2.28 ``` 如果命令输出 GLIBC_2.28,则表示已成功安装 GLIBC 2.28 版本。 请注意,安装特定版本的软件可能会对您的系统产生不利影响。因此,请确保您已经备份了所有重要的文件,并在安装之前进行测试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值