centos7.9 安装 nodejs(包含安装fnm、更换yum源、升级 gcc、make、glibc、libstdc++)

WinterSir's Blog / 2024-10-17 / 原文

1、安装fnm

(1)压缩包fnm-linux.zip搞到服务器上,我放在root里。
(2)解压、设置权限

unzip fnm-linux.zip
chmod 777 fnm

(3)设置环境变量,添加到/etc/profile文件末尾,配置生效

export PATH=$PATH:/root  
source /etc/profile

(4)添加到~/.bashrc文件末尾

eval "$(fnm env --use-on-cd --shell bash)"
source ~/.bashrc

查看fnm版本命令验证是否安装成功

fnm --version
fnm 1.37.2

2、下载并安装 Node.js

fnm use --install-if-missing 20

3、验证 Node.js 版本

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)

4、安装依赖前,先换阿里云yum源(换过的请跳过)

(1)更换阿里云yum源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

(2)查看你安装的scl

yum list installed|grep "scl"

(3)删除

yum remove centos-release-scl.noarch
yum remove centos-release-scl-rh.noarch

(4)重新安装

yum install -y centos-release-scl centos-release-scl-rh

(5)配置scl国内源阿里云
文件 CentOS-SCLo-scl.repo

[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

文件 CentOS-SCLo-scl-rh.repo

[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

(6)清理缓存

yum clean all && yum makecache

坑我踩过了,5、6、7、8 按这个顺序安装

5、升级 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++

6、升级 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 --disable-dependency-tracking
make && make install
cd /usr/bin/ && mv make make.bak
ln -sv /usr/local/make/bin/make /usr/bin/make

7、升级 glibc

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
make && make install

8、升级 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

“降龙8掌”打完了,收工

node -v
v20.17.0