方法1
wget https://nodejs.org/dist/v16.14.2/node-v16.14.2-linux-x64.tar.xz
tar -xvf node-v16.14.2-linux-x64.tar.xz
mv node-v16.14.2-linux-x64 /usr/local/
ln -s /usr/local/node-v16.14.2-linux-x64/bin/npm /usr/local/bin/npm
ln -s /usr/local/node-v16.14.2-linux-x64/bin/node /usr/local/bin/node
方法2(推荐)
curl -o node-v16.14.2.tar.xz https://nodejs.org/dist/v16.14.2//node-v16.14.2-linux-x64.tar.xz
VERSION=v16.14.2
DISTRO=linux-x64
sudo mkdir /usr/local/lib/nodejs
sudo tar -xJvf node-$VERSION.tar.xz -C /usr/local/lib/nodejs
sudo mv /usr/local/lib/nodejs/node-v16.14.2-linux-x64 /usr/local/lib/nodejs/node-v16.14.2
export NODEJS_HOME=/usr/local/lib/nodejs/node-v16.14.2/bin
export PATH=$NODEJS_HOME:$PATH
cat >> /etc/profile <<EOF
export NODEJS_HOME=/usr/local/lib/nodejs/node-v16.14.2/bin
export PATH=$NODEJS_HOME:$PATH
EOF
source /etc/profile
ln -s /usr/local/lib/nodejs/node-v16.14.2/bin/npm /usr/local/bin/npm
ln -s /usr/local/lib/nodejs/node-v16.14.2/bin/node /usr/local/bin/node
ln -s /usr/local/lib/nodejs/node-v16.14.2/bin/pm2 /usr/local/bin/pm2