参考文档:https://github.com/nodejs/help/wiki/Installation

下载二进制文件

可以本地下载后上传,也可以通过wget下载

mkdir -p /data/soft/nodejs && cd /data/soft/nodejs
wget https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz
tar xf  node-v20.10.0-linux-x64.tar.xz
cd node-v20.10.0-linux-x64
# 测试是否安装成功
[root@VM-32-8-centos node-v20.10.0-linux-x64]# ./bin/node -v
v20.10.0

复制到指定目录

 cp -r /data/soft/nodejs/node-v20.10.0-linux-x64 /usr/local/lib/nodejs/

设置环境变量

Set the environment variable ~/.profile, add below to the end

# Nodejs
VERSION=v20.10.0
DISTRO=linux-x64
export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH

Refresh profile

source ~/.profile