检查 Glibc 版本

1
ldd --version

安装 glibc-2.28

编译时间可能会很长,最好找个空闲时间来升级。

1
2
3
4
5
6
7
8
9
10
11
12
13
# 下载并解压 glibc-2.28
yum install -y bison
cd /usr/src/
wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar -xzvf 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

# 这一步时,如果发生如下错误,则需要进行 gcc & make 的升级,否则进行最后一步【继续编译 glibc】
# These critical programs are missing or too old: make compiler

升级 GCC 与 Make

安装 GLIBC 所需的依赖可以在 glibc 目录下的 INSTALL 中找到,该版本需要 GCC 4.9 以上及 make 4.0 以上。

升级 Make

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd /usr/src/
wget https://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 # backup
ln -sv /usr/local/make/bin/make /usr/bin/make

升级 GCC

mirrorlist.centos.org 源不再维护,当执行 yum 指令时可能报错:Could not resolve host: mirrorlist.centos.org; Unknown error

可参考 CentOS 7 源替换成可用源。

1
2
3
4
5
6
7
8
9
10
11
# 直接安装 GCC-8.3.1
yum install centos-release-scl-rh -y
yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils

# 临时生效,执行:
scl enable devtoolset-8 bash
# 会新创建一个 bash 会话,键入 exit 即可退出

# 如果想要永久生效,可以执行:
echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile
source /etc/profile

继续编译 glibc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 进入之前的 `/usr/src/glibc-2.28/build` 目录下
cd /usr/src/glibc-2.28/build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

# 每 4 条指令并行执行
make -j 4

# 此步可能会遇到报错:`Btw. the script doesn't work if you're installing GNU libc not as your`,但似乎不影响
make install

# 查询
strings /lib64/libc.so.6 | grep GLIBC
# ...
# GLIBC_2.22
# GLIBC_2.23
# GLIBC_2.24
# GLIBC_2.25
# GLIBC_2.26
# GLIBC_2.27
# GLIBC_2.28
# GLIBC_PRIVATE
# ...

# 版本验证
ldd --version

升级 libstdc++.so.6

当安装 nodejs18+ 发现以下错误:

1
2
3
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++.so.6

1
2
3
4
cd /usr/local/lib64
wget http://www.vuln.cn/wp-content/uploads/2019/08/libstdc.so_.6.0.26.zip
mv /usr/local/lib64/libstdc++.so.6.0.26 /usr/local/lib64/libstdc++.so.6
ln -fs /usr/local/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6

问题

升级完后报错:can't set the locale; make sure $LC_* and $LANG are correct

查看以下几个文件中是否有多余的语言配置,如果有,清除掉:

1
2
3
/etc/environment
/etc/locale.gen
/etc/locale.conf

然后执行:

1
localedef -i en_US -f UTF-8 en_US.UTF-8