centos 安装Nodejs v20.11.1

centos 方法

curl 直接安装
[root] curl -fsSL https://github.com/Schniz/fnm/raw/master/.ci/install.sh | bash


Checking dependencies for the installation script...
Checking availability of curl... OK!
Checking availability of unzip... OK!
Downloading https://github.com/Schniz/fnm/releases/latest/download/fnm-linux.zip...
######################################################################## 100.0%
Installing for Bash. Appending the following to /root/.bashrc:

  # fnm
  export PATH="/root/.local/share/fnm:$PATH"
  eval "`fnm env`"

In order to apply the changes, open a new terminal or run the following command:

  source /root/.bashrc

添加环境变量
[root] echo 'eval "$(fnm env --multi)"' >> ~/.bashrc
# 加载
[root] source ~/.bashrc
# 验证
[root] fnm -V
fnm 1.35.1

# 出现 warning: --multi is deprecated. This is now the default. 时
[root] vim ~/.bashrc
#修改 eval "$(fnm env --multi)"
eval "$(fnm env)"
安装Nodejs
[root] fnm install v20
Installing Node v20.11.1 (x64)
[root] fnm use v20.11.1
Using Node v20.11.1
错误解决

在验证使用的node版本的时候,出现如下问题,这个是系统的依赖库版本低了,需要升级gcc glibc_2.28

[root] node -V
node: /lib64/libm.so.6: version `GLIBC_2.27' 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 `CXXABI_1.3.9' not found (required by node)
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node)
升级gcc
$ yum update
# 升级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++

# 升级 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
 
#验证gcc版本
$ gcc -v
升级 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 --enable-obsolete-nsl
$ make -j 10
$ make localedata/install-locales -j 10
$ make install -j 10
遇到错误

checking for python3... python3
configure: error:
*** These critical programs are missing or too old: bison
*** Check the INSTALL file for required versions.
解决办法

 $ yum install bison

 # 安装后执行安装glibc
 
 # 再次遇到错误
/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 '/www/tools/glibc-2.28'
make: *** [Makefile:12: install] Error 2

解决办法

$ vim scripts/test-installation.pl

在文件的128行新增$name ne “nss_test2”,如下图所示:

重新执行glibc安装命令,可顺利安装,然后校验

$ node -V
node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' 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.21' not found (required by node)

仍有部分报错需要解决,出现/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found的问题,是因为生成的动态库没有替换老版本gcc的动态库导致的。将gcc最新版本的动态库替换系统中老版本的动态库即可解决。

# 先试用yum版本,看看能否解决问题,如果不能解决问题,用后面方法。
$ strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
$ strings /lib64/libstdc++.so.6 | grep GLIBCXX

$ 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

参考链接:
centos7升级glibc2.28_centos7 glibc2.28-优快云博客
centos7 glibc2.17升级到glibc2.28_glibc 2.28-优快云博客

https://www.cnblogs.com/even160941/p/17319119.html

解决:centos7 中node: /lib64/libm.so.6: version `GLIBC_2.27‘ not found (required by node)_node: /lib64/libm.so.6: version `glibc_2.27' not f-优快云博客

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值