Centos下安装Node18+版本
大熊•
背景
因为服务器的版本过低(centos7),导致Node18安装失败。本文记录了升级过程,希望遇到相似问题的同学能够提供帮助。
centos7服务器使用nvm安装的node之后,只要使用npm或者node,均会出现以下问题
npm -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版本, 然后再根据分析可得知 新版的node v18开始 都需要GLIBC_2.27支持,可是目前系统内却没有那么高的版本。
strings /lib64/libc.so.6 |grep GLIBC_
GLIBC_2.2.5
...
GLIBC_2.17
....
解决办法
更新glibc
根据提示安装所需要的glibc-2.28
wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar xf 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
可能出现的错误
上步更新 glibc 可能会发生错误。如果没有错误 下边这一步 不用看。
- make问题
configure: error:
*** These critical programs are missing or too old: make bison compiler
*** Check the INSTALL file for required versions.
解决办法:升级gcc与make
# 升级GCC(默认为4 升级为8)</span>
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++
# 升级 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
这时 所有的问题 都已经解决完毕 再重新执行上一步 更新glibc即可
cd /${yourpath}/glibc-2.28/build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/opt/rh/devtoolset-11/root/usr/bin --disable-werror
- 如果依旧报错:bison太老旧
configure: error:
*** These critical programs are missing or too old: bison
*** Check the INSTALL file for required versions.
查看bison版本多少
bison -v
-bash: bison: 未找到命令
如果没有装则执行安装yum install -y bison
这时 所有的问题 真的真的都已经解决完毕 再重新执行上一步 更新glibc即可
cd /root/glibc-2.28/build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/opt/rh/devtoolset-11/root/usr/bin --disable-werror
- 如果GCC明明版本已经升级了但是还是提示编译器版本低,是因为旧版本的GCC在作怪。 所以如下参数:
--with-binutils=/opt/rh/devtoolset-11/root/usr/bin
新版本GCC
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC)
- 如果make的时候会因为note出现错误。可以通过加入参数:
--disable-werror
继续更新
make 和 make install在linux中就是安装软件的意思 简单这么理解就好。
这个过程较长,大约半小时左右,建议打一局游戏就好了。
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/system-upgrade/glibc-2.28'
make: *** [Makefile:12:install] 错误 2
这块其实不用太在意,执行命令ldd --version
如果出现版本信息ldd (GNU libc) 2.28
就OK了。
- 如果还是出现下面的问题,要连接新的动态库
npm -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)
用命令查看 strings /usr/lib64/libstdc++.so.6 | grep CXXABI
更新 libstdc++.so.6.0.26
# 更新lib libstdc++.so.6.0.26
wget https://cdn.frostbelt.cn/software/libstdc%2B%2B.so.6.0.26
# 替换系统中的/usr/lib64
cp libstdc++.so.6.0.26 /usr/lib64/
cd /usr/lib64/
ln -snf ./libstdc++.so.6.0.26 libstdc++.so.6
验证
执行完成后验证下 npm -v
后出现正确的版本。