Linux安装:node环境

1、Linux 安装 node

下载node20安装包到 /opt 目录,并解压

cd /opt
wget https://nodejs.org/dist/v20.12.2/node-v20.12.2-linux-x64.tar.xz --no-check-certificate

解压

tar -xvf node-v20.12.2-linux-x64.tar.xz

配置环境变量

vim /etc/profile

export NODE_HOME=/opt/node-v20.12.2-linux-x64
export PATH=$PATH:${NODE_HOME}/bin

刷新配置

source /etc/profile

检查node版本号

node -V

 

Centos7安装node20的依赖问题

因为Centos7系统比较旧,使用node20缺少了很多依赖,所以安装起来比较麻烦。

升级基础包

yum update

升级GCC

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

cd /usr/local/
wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar -xzvf make-4.3.tar.gz && cd make-4.3/
mkdir /usr/local/make
./configure --prefix=/usr/local/make
make && make install
cd /usr/bin/
ln -sv /usr/local/make/bin/make /usr/bin/make

验证gcc版本

gcc -v

升级glibc-2.28

cd /usr/local/
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

升级libstdc++

yum provides libstdc++.so.6

cd /usr/local/lib64
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 /usr/lib64
cd /usr/lib64
ls -l | grep libstdc++
libstdc++.so.6 ->libstdc++.so.6.0.19

rm libstdc++.so.6

ln -s libstdc++.so.6.0.26 libstdc++.so.6

查看新版本,成功

strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX

...
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
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_DEBUG_MESSAGE_LENGTH
...

检查node版本号

node -V