1、安装nvm
通过nvm来管理多本版npm,先安装nvm
下载地址:https://github.com/nvm-sh/nvm/tags
根据实际需要选择版本
[root@centos dl]# wget https://github.com/nvm-sh/nvm/archive/refs/tags/v0.39.5.tar.gz
[root@centos dl]# tar -zxvf v0.39.5.tar.gz
[root@centos dl]# mv nvm-0.39.5 /data/nvm
[root@centos dl]# echo "source /data/nvm/nvm.sh" >> /etc/profile
[root@centos dl]# source /etc/profile
#查看npm版本
[root@centos dl]# nvm list-remote
#安装npm
[root@centos dl]# nvm install v18.18.0
#切换npm版本
[root@centos dl]# nvm use v18.18.0
#安装npm之后可能会遇到这样的错误
[root@centos dl]# npm
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和GLIBCXX_3.4.21
2、升级GLIBC_2.28
#下载GLIBC_2.28
[root@centos dl]# wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
[root@centos dl]# tar -zxvf glibc-2.28.tar.gz
[root@centos dl]# cd glibc-2.28/
[root@centos glibc-2.28]# mkdir build
[root@centos glibc-2.28]# cd build/
[root@centos 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
*** Check the INSTALL file for required versions.
[root@centos build]#
#首先升级gcc-8
[root@centos build]# cat /etc/yum.repos.d/scl.repo
[CentOS-SCLo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
enabled=1
gpgcheck=0
[CentOS-SCLo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
enabled=1
gpgcheck=0
#安装依赖
[root@centos build]# yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
[root@centos build]# echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile
[root@centos build]# source /etc/profile
#升级make
[root@centos dl]# wget https://ftp.gnu.org/gnu/make/make-4.3.tar.gz
[root@centos dl]# tar -xzvf make-4.3.tar.gz
[root@centos dl]# cd make-4.3/
#安装到指定目录
[root@centos make-4.3]# ./configure --prefix=/usr/local/make
[root@centos make-4.3]# make
[root@centos make-4.3]# make install
#创建软链接
[root@centos make-4.3]# cd /usr/bin/
[root@centos bin]# mv make make.bak
[root@centos bin]# ln -sv /usr/local/make/bin/make /usr/bin/make
[root@centos bin]# make -v
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.
[root@centos bin]#
回到之前GLIBC_2.28目录
[root@centos build]# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
可能会出现类似这样的错误
configure: WARNING: *** These auxiliary programs are missing or incompatible versions: makeinfo *** some features or tests will be disabled. *** Check the INSTALL file for required versions. checking LD_LIBRARY_PATH variable... contains current directory configure: error: *** LD_LIBRARY_PATH shouldn't contain the current directory when *** building glibc. Please change the environment variable *** and run configure again.
导致的原因是因为LD_LIBRARY_PATH这个变量的值中有:导致的,把最后的:去掉
[root@centos build]# echo $LD_LIBRARY_PATH /opt/rh/devtoolset-8/root/usr/lib64:/opt/rh/devtoolset-8/root/usr/lib:/opt/rh/devtoolset-8/root/usr/lib64/dyninst:/opt/rh/devtoolset-8/root/usr/lib/dyninst:/opt/rh/devtoolset-8/root/usr/lib64:/opt/rh/devtoolset-8/root/usr/lib:/usr/local/lib: [root@centos build]# LD_LIBRARY_PATH="/opt/rh/devtoolset-8/root/usr/lib64:/opt/rh/devtoolset-8/root/usr/lib:/opt/rh/devtoolset-8/root/usr/lib64/dyninst:/opt/rh/devtoolset-8/root/usr/lib/dyninst:/opt/rh/devtoolset-8/root/usr/lib64:/opt/rh/devtoolset-8/root/usr/lib:/usr/local/lib" [root@centos build]#
重新编译
又出现这个错误
configure: error:
*** These critical programs are missing or too old: bison
*** Check the INSTALL file for required versions.
[root@centos build]# bison -V
bash: bison: command not found
#竟然没有安装,装
[root@centos build]# yum -y install bison
#再继续之前的步骤
[root@centos build]# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
[root@centos build]# make && make install
如果最后安装出现这样的错误可以忽略
collect2: error: ld returned 1 exit status Execution of gcc -B/usr/bin/ failed! The script has found some problems with your installation! Please read the FAQ and the README file and check the following: - Did you change the gcc specs file (necessary after upgrading from Linux libc5)? - Are there any symbolic links of the form libXXX.so to old libraries? Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong, libm.so should point to the newly installed glibc file - and there should be only one such link (check e.g. /lib and /usr/lib) You should restart this script from your build directory after you've fixed all problems! Btw. the script doesn't work if you're installing GNU libc not as your primary library! make[1]: *** [Makefile:111: install] Error 1 make[1]: Leaving directory '/data/dl/glibc-2.28' make: *** [Makefile:12: install] Error 2
3、升级GLIBCXX_3.4.21
需要用gcc7的包
#查看
[root@centos dl]# strings /usr/lib64/libstdc++.so.6 | grep -i 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
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19 #支持的最高版本
GLIBC_2.3
GLIBC_2.2.5
GLIBC_2.14
GLIBC_2.4
GLIBC_2.3.2
GLIBCXX_DEBUG_MESSAGE_LENGTH
[root@centos dl]#
# 下载gcc7.3.0对应的glibc源代码
[root@centos dl]# wget http://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
[root@centos dl]# tar -zxvf gcc-7.3.0.tar.gz
[root@centos dl]# cd gcc-7.3.0
[root@centos gcc-7.3.0]# ./contrib/download_prerequisites
2023-12-07 21:39:25 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2023-12-07 21:39:33 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
2023-12-07 21:39:39 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [1]
2023-12-07 21:39:48 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.16.1.tar.bz2 [1626446] -> "./isl-0.16.1.tar.bz2" [1]
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: OK
isl-0.16.1.tar.bz2: OK
All prerequisites downloaded successfully.
[root@centos gcc-7.3.0]# mkdir build
[root@centos gcc-7.3.0]# cd build/
[root@centos build]# ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
#make时间比较长
[root@centos build]# make
#安装
[root@centos build]# make install
#安装完成后操作
[root@centos build]# cp /usr/local/lib64/libstdc++.so.6.0.24 /usr/lib64/
[root@centos lib64]# cd /usr/lib64/
[root@centos lib64]# ll libstdc++.so.6
lrwxrwxrwx. 1 root root 19 Jun 27 2021 libstdc++.so.6 -> libstdc++.so.6.0.19
[root@centos lib64]# rm -rf libstdc++.so.6
[root@centos lib64]# ln -s libstdc++.so.6.0.
[root@centos lib64]# ln -s libstdc++.so.6.0.24 libstdc++.so.6
#查看安装的新版本
[root@centos lib64]# strings 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
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_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.14
GLIBC_2.18
GLIBC_2.16
GLIBC_2.17
GLIBC_2.3.2
GLIBCXX_DEBUG_MESSAGE_LENGTH
所需的依赖升级完成,执行npm查看 是否还会报错
[root@centos lib64]# npm version
{
npm: '9.8.1',
node: '18.18.0',
acorn: '8.10.0',
ada: '2.6.0',
ares: '1.19.1',
brotli: '1.0.9',
cldr: '43.1',
icu: '73.2',
llhttp: '6.0.11',
modules: '108',
napi: '9',
nghttp2: '1.55.0',
nghttp3: '0.7.0',
ngtcp2: '0.8.1',
openssl: '3.0.10+quic',
simdutf: '3.2.14',
tz: '2023c',
undici: '5.22.1',
unicode: '15.0',
uv: '1.46.0',
uvwasi: '0.0.18',
v8: '10.2.154.26-node.26',
zlib: '1.2.13.1-motley'
}
[root@centos lib64]#