本文整合网上几篇帖子来补充我在安装时遇到的问题以及处理办法,
阅读前提是安装好nvm nvm可以正常安装node16.x版本 切换到18.x 版本以上在调用node -v 或者npm -v 会报图上的错误
一、下载node v18.16.0
- 下载地址:https://nodejs.org/dist/
- https://nodejs.org/en/download/releases
- 解压,查看node版本号
[dev1@localhost bin]$ ./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版本strings /lib64/libc.so.6 |grep GLIBC
[dev1@localhost bin]$ strings /lib64/libc.so.6 |grep GLIBC GLIBC_2.2.5 GLIBC_2.2.6 GLIBC_2.3 GLIBC_2.3.2 GLIBC_2.3.3 GLIBC_2.3.4 GLIBC_2.4 GLIBC_2.5 GLIBC_2.6 GLIBC_2.7 GLIBC_2.8 GLIBC_2.9 GLIBC_2.10 GLIBC_2.11 GLIBC_2.12 GLIBC_2.13 GLIBC_2.14 GLIBC_2.15 GLIBC_2.16 GLIBC_2.17 GLIBC_PRIVATE ___sys_nerr_GLIBC_2_3 ___sys_nerr_GLIBC_2_4 ___sys_nerr_GLIBC_2_1 ___sys_errlist_GLIBC_2_1 ___sys_errlist_GLIBC_2_4 ___sys_errlist_GLIBC_2_3 _IO_file_seekoff@@GLIBC_2.2.5 getservent_r@@GLIBC_2.2.5 _sys_siglist@@GLIBC_2.3.3 _dl_starting_up@@GLIBC_PRIVATE tmpfile@@GLIBC_2.2.5 sched_getaffinity@GLIBC_2.3.3 pthread_cond_wait@GLIBC_2.2.5 regexec@GLIBC_2.2.5 memcpy@@GLIBC_2.14 _IO_file_init@@GLIBC_2.2.5 realpath@GLIBC_2.2.5 realpath@@GLIBC_2.3 __ctype32_tolower@GLIBC_2.2.5 gethostbyname2_r@@GLIBC_2.2.5 getaliasbyname_r@@GLIBC_2.2.5 _IO_file_overflow@@GLIBC_2.2.5 pthread_cond_wait@@GLIBC_2.3.2 getprotoent_r@@GLIBC_2.2.5 regexec@@GLIBC_2.3.4 _rtld_global@@GLIBC_PRIVATE getgrgid_r@@GLIBC_2.2.5 pthread_cond_init@GLIBC_2.2.5 _IO_fsetpos@@GLIBC_2.2.5 GLIBC_2.8 _IO_proc_close@@GLIBC_2.2.5 _sys_nerr@@GLIBC_2.12 pthread_cond_timedwait@@GLIBC_2.3.2 __libc_enable_secure@@GLIBC_PRIVATE pclose@@GLIBC_2.2.5 getaliasent_r@@GLIBC_2.2.5 __tls_get_addr@@GLIBC_2.3 _sys_nerr@GLIBC_2.4 sys_sigabbrev@GLIBC_2.2.5 pthread_cond_broadcast@GLIBC_2.2.5 _IO_proc_open@@GLIBC_2.2.5 posix_spawn@@GLIBC_2.15 getpwnam_r@@GLIBC_2.2.5 _rtld_global_ro@@GLIBC_PRIVATE getrpcbyname_r@@GLIBC_2.2.5 pthread_cond_broadcast@@GLIBC_2.3.2 nftw64@GLIBC_2.2.5 _sys_siglist@GLIBC_2.2.5 _sys_nerr@GLIBC_2.3 _IO_fsetpos64@@GLIBC_2.2.5 __ctype_tolower@GLIBC_2.2.5 __ctype_toupper@GLIBC_2.2.5 _IO_file_underflow@@GLIBC_2.2.5 localeconv@@GLIBC_2.2.5 pthread_cond_timedwait@GLIBC_2.2.5 _IO_file_fopen@@GLIBC_2.2.5 __ctype_b@GLIBC_2.2.5 GLIBC_2.5 _IO_file_finish@@GLIBC_2.2.5 GLIBC_2.9 getgrnam_r@@GLIBC_2.2.5 GLIBC_2.7 GLIBC_2.6 getservbyname_r@@GLIBC_2.2.5 __ctype32_b@GLIBC_2.2.5 _res@GLIBC_2.2.5 __secure_getenv@GLIBC_2.2.5 getnetent_r@@GLIBC_2.2.5 nftw@GLIBC_2.2.5 getpwuid_r@@GLIBC_2.2.5 _IO_fdopen@@GLIBC_2.2.5 posix_spawn@GLIBC_2.2.5 gethostbyaddr_r@@GLIBC_2.2.5 _IO_file_xsputn@@GLIBC_2.2.5 pthread_attr_init@@GLIBC_2.2.5 getrpcbynumber_r@@GLIBC_2.2.5 _IO_fopen@@GLIBC_2.2.5 getnetbyname_r@@GLIBC_2.2.5 memcpy@GLIBC_2.2.5 pthread_cond_signal@@GLIBC_2.3.2 pthread_cond_signal@GLIBC_2.2.5 sys_sigabbrev@@GLIBC_2.3.3 _IO_fgetpos@@GLIBC_2.2.5 posix_spawnp@@GLIBC_2.15 _IO_file_setbuf@@GLIBC_2.2.5 getservbyport_r@@GLIBC_2.2.5 _sys_errlist@GLIBC_2.3 _IO_file_attach@@GLIBC_2.2.5 gethostent_r@@GLIBC_2.2.5 _sys_errlist@GLIBC_2.4 _sys_nerr@GLIBC_2.2.5 nftw64@@GLIBC_2.3.3 _IO_fgetpos64@@GLIBC_2.2.5 __res_maybe_init@GLIBC_PRIVATE fnmatch@@GLIBC_2.2.5 h_errno@GLIBC_PRIVATE _sys_errlist@@GLIBC_2.12 _IO_fclose@@GLIBC_2.2.5 gethostbyname_r@@GLIBC_2.2.5 _IO_do_write@@GLIBC_2.2.5 getspent_r@@GLIBC_2.2.5 getpwent_r@@GLIBC_2.2.5 pthread_cond_destroy@GLIBC_2.2.5 sched_setaffinity@GLIBC_2.3.3 getspnam_r@@GLIBC_2.2.5 sched_setaffinity@@GLIBC_2.3.4 _IO_popen@@GLIBC_2.2.5 getgrent_r@@GLIBC_2.2.5 _IO_file_sync@@GLIBC_2.2.5 GLIBC_2.11 GLIBC_2.16 GLIBC_2.10 pthread_cond_init@@GLIBC_2.3.2 GLIBC_2.17 getprotobyname_r@@GLIBC_2.2.5 GLIBC_2.13 getnetbyaddr_r@@GLIBC_2.2.5 _sys_errlist@GLIBC_2.2.5 _IO_file_write@@GLIBC_2.2.5 pthread_cond_destroy@@GLIBC_2.3.2 nftw@@GLIBC_2.3.3 GLIBC_2.2.6 fopencookie@@GLIBC_2.2.5 __ctype32_toupper@GLIBC_2.2.5 sched_getaffinity@@GLIBC_2.3.4 _dl_argv@@GLIBC_PRIVATE posix_spawnp@GLIBC_2.2.5 getrpcent_r@@GLIBC_2.2.5 getprotobynumber_r@@GLIBC_2.2.5 _IO_file_close_it@@GLIBC_2.2.5 _obstack@GLIBC_2.2.5 [dev1@localhost bin]$
可以看到,我们centos7上安装的GLIBC版本是2.2.5,而node所需的GLIBC版本是GLIBC_2.27、GLIBC_2.25、GLIBC_2.28,
所以报错的原因是,glibc版本过低 - 解决方案:升级glibc
二、下载glibc2.28(建议使用第二个,第一个很慢的)
-
http://ftp.gnu.org/pub/gnu/glibc/
http://www.gnu.org/software/libc/libc.html
http://mirrors.nju.edu.cn/gnu/libc/
http://ftp.ntu.edu.tw/gnu/glibc/
http://mirrors.syringanetworks.net/gnu/libc/
http://alpha.gnu.org/gnu/glibc/三、升级glibc2.28前置条件
- 查看升级glibc2.28所需编译器的版本号
我们查看安装包内的文件INSTALL - 显示如下
Recommended Tools for Compilation ================================= We recommend installing the following GNU tools before attempting to build the GNU C Library: * GNU 'make' 4.0 or newer As of relase time, GNU 'make' 4.2.1 is the newest verified to work to build the GNU C Library. * GCC 4.9 or newer GCC 4.9 or higher is required.
- 可知,需要make4.0以后的版本,最新验证过的make版本是4.2.1
- 可知,需要gcc4.9或者更新版本。
四、查看本机的gcc版本、make版本
- gcc-4.8.2
[dev1@localhost build]$ gcc -v 使用内建 specs。 COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper 目标:x86_64-redhat-linux 配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux 线程模型:posix gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) [dev1@localhost build]$
- make
[dev1@localhost build]$ make -v 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. [dev1@localhost build]$
五、升级gcc4.9
1、源码编译安装——(不建议使用)
- 下载 gcc-4.9.0.tar.bz2
wget https://mirrors.ustc.edu.cn/gnu/gcc/gcc-4.9.0/gcc-4.9.0.tar.bz2 tar -jxvf gcc-4.9.0.tar.bz2 cd gcc-4.9.0 ./contrib/download_prerequisites mkdir build && cd build ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib ../configure --prefix=/usr/local/gcc --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib make -j4 && sudo make install
- 导出环境变量
[dev1@localhost ~]$ sudo vi /etc/profile.d/gcc.sh export PATH=/usr/local/gcc/bin:$PATH [dev1@localhost ~]$ source /etc/profile.d/gcc.sh [dev1@localhost ~]$ gcc -v 使用内建 specs。 COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/local/gcc/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper 目标:x86_64-unknown-linux-gnu 配置为:../configure --prefix=/usr/local/gcc --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib 线程模型:posix gcc 版本 4.9.0 (GCC) [dev1@localhost ~]$
2、devtoolset安装升级gcc4.9:(不建议使用)
-
sudo yum update wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo --no-check-certificate yum -y install devtoolset-3-gcc devtoolset-3-gcc-c++ devtoolset-3-binutils scl enable devtoolset-3 bash
2.1、devtoolset离线下载、安装
- 离线下载-devtoolset
-
sudo yum update wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo --no-check-certificate sudo yum install --downloadonly devtoolset-3 --downloaddir=devtoolset-3 --skip-broken
- 离线安装-devtoolset
cd devtoolset-3 sudo rpm -Uvh --force *.rpm
如果报错:
错误:依赖检测失败:libqudamath = 4.8.5 - 39.el7 被 (已安装) libgfortran - 4.8.5 - 39.el7.x86_64
下面的解决方案不建议使用,因为可能会引起:重启系统失败。所以,建议的解决方案是——使用离线安装的centos系统制作离线版本的devtoolset,然后再拷贝到局域网安装。
-
原因和解决方案
这个错误表示,在安装某个软件包时,Yum 检测到系统中已经存在 libgfortran,但它的版本与所需版本不匹配。 具体来说,安装程序需要的是 libqudamath 4.8.5-39.el7,但系统中已经安装的 libgfortran 是 4.8.5-39.el7.x86_64,因此无法满足依赖关系。 为了解决这个问题,可以按以下步骤操作: 卸载已安装的 libgfortran。 首先需要卸载系统中已经安装的 libgfortran。使用以下命令可以查看已安装的 libgfortran 版本: rpm -qa | grep libgfortran 然后使用以下命令卸载指定版本的 libgfortran: sudo rpm -e --nodeps libgfortran-4.8.5-39.el7.x86_64 其中,--nodeps 选项表示忽略依赖关系检查,强制删除软件包。这里需要将命令中的版本号替换为实际安装的版本。
- 使用devtoolset
临时使用
scl enable devtoolset-3 bash
或者
source /opt/rh/devtoolset-3/enable
当前账户永久使用
~/.profile文件假如以下内容source /opt/rh/devtoolset-3/enable
所有账户永久使用
打开/etc/profile.d/devtoolset.sh 文件:
把以下内容加入文件source /opt/rh/devtoolset-3/enable
其他版本参靠为CentOS 6、7升级gcc至4.8、4.9、5.2、6.3、7.3等高版本
升级到gcc 7.3: yum -y install centos-release-scl yum -y install devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-binutils scl enable devtoolset-7 bash 需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。 如果要长期使用gcc 7.3的话: echo "source /opt/rh/devtoolset-7/enable" >>/etc/profile 升级到gcc 8.3: yum -y install centos-release-scl yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils scl enable devtoolset-8 bash 需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。 如果要长期使用gcc 8.3的话: echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile 升级到gcc 9.3: yum -y install centos-release-scl yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable devtoolset-9 bash 需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。 如果要长期使用gcc 9.3的话: echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile 再说一下已经停止支持的devtoolset4(gcc 5.2)及之前版本的安装方法 升级到gcc 4.8: wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtoolset-2.repo yum -y install devtoolset-2-gcc devtoolset-2-gcc-c++ devtoolset-2-binutils scl enable devtoolset-2 bash 升级到gcc4.9: wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo yum -y install devtoolset-3-gcc devtoolset-3-gcc-c++ devtoolset-3-binutils scl enable devtoolset-3 bash 升级到gcc 5.2 wget https://copr.fedoraproject.org/coprs/hhorak/devtoolset-4-rebuild-bootstrap/repo/epel-6/hhorak-devtoolset-4-rebuild-bootstrap-epel-6.repo -O /etc/yum.repos.d/devtoolset-4.repo yum install devtoolset-4-gcc devtoolset-4-gcc-c++ devtoolset-4-binutils -y scl enable devtoolset-4 bash 升级完成后一定要运行:gcc --version 看一下版本号变成升级后的gcc版本才算升级成功。
3、gcc 7.3(建议)
-
gcc73之前的,在某些系统上,安装处理依赖会有些问题,所以建议从7.3开始使用。(一般高版本的对低版本的会做兼容处理,如果你真的一定要4.9,建议前面两种方法,但是中间可能会有相关问题,且源码编译的时间特别长)
升级到gcc 7.3: yum -y install centos-release-scl yum -y install devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-binutils scl enable devtoolset-7 bash 需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。 如果要长期使用gcc 7.3的话: echo "source /opt/rh/devtoolset-7/enable" >>/etc/profile
重启后生效
六、升级make4.1.0
-
- 下载、构建、安装
wget http://mirrors.ustc.edu.cn/gnu/make/make-4.3.tar.gz $ tar -xzvf make-4.3.tar.gz $ cd make-4.3/ # 创建构建目录 mkdir build && cd build # 安装到指定目录 $ ../configure --prefix=/usr/local/make $ make -j4 && sudo make install # 创建软链接 $ cd /usr/bin/ $ mv make make.bak # backup $ ln -sv /usr/local/make/bin/make /usr/bin/make
- 验证
[dev1@localhost bin]$ make -v GNU Make 4.2.1 为 x86_64-pc-linux-gnu 编译 Copyright (C) 1988-2016 Free Software Foundation, Inc. 许可证:GPLv3+:GNU 通用公共许可证第 3 版或更新版本<http://gnu.org/licenses/gpl.html>。 本软件是自由软件:您可以自由修改和重新发布它。 在法律允许的范围内没有其他保证。 [dev1@localhost bin]$
- 下载、构建、安装
六、现在可以安装glibc了
# 在线安装
wget http://mirrors.ustc.edu.cn/gnu/libc/glibc-2.28.tar.gz
# 解压
tar zxf 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 --disable-sanity-checks --disable-werror
# 这步执行时间依赖你的配置,我的4核虚拟机,大概30多分钟
make -j8
make install
sudo make localedata/install-locales
验证
ls -l /lib/libc.so.6
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 '/home/dev1/下载/glibc-2.28'
make: *** [Makefile:12:install] 错误 2
[root@localhost build]# ls -l /lib64/libc.so.6
lrwxrwxrwx. 1 root root 12 Jun 8 22:45 /lib64/libc.so.6 -> libc-2.28.so
[root@localhost build]#
到此就完成了,如果你遇到了其他问题,可以继续往后看,看是否有你需要的。
七、安装glibc可能会遇到的问题
问题0:重新启动后,发现右击桌面,打不开terminal了
原因,你应该是没有进行下面的这行,没安装字符集
sudo make localedata/install-locales
在glibc-2.28/build/目录下执行上面的命令行。
问题1:Centos 7 升级 Glibc-2.28,报错,
collect2: error: ld returned 1 exit status ,execution of gcc -B /usr/bin/ failed
/usr/bin/ld: cannot find -lnss_test2
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 '/home/dev1/下载/glibc-2.28'
make: *** [Makefile:12: install] Error 2
[root@localhost build]# ls -l /lib/libc.so.6
编译前打开
vim scripts/test-installation.pl
在文件的128行新增$name ne “nss_test2”,如下图所示:
解决动态库 undefined reference to '_nsl_default_nss@GLIBC_PRIVATE'
这个看下nis/Makefile
71 ifeq ($(build-obsolete-nsl),yes) 72 libnsl-routines += nss-default
configure
增加 --enable-obsolete-nsl
#configure --help --enable-obsolete-nsl build and install the obsolete libnsl library and depending NSS modules
按照下面格式重新调整一下,重新编译就可以了
../configure --prefix=/usr --with-headers=/usr/include --with-binutils=/usr/bin --enable-obsolete-nsl
如果glibc 安装之后还是 运行node -v 还是报错
那就需要升级 libstdc++
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
最后再安装最新nodejs 这样就可以正常运行了