二进制安装
1.下载解压wget https://cdn.npm.taobao.org/dist/node/v12.16.2/node-v12.16.2-linux-x64.tar.xz
tar -xf node-v12.16.2-linux-x64.tar.xz
mv node-v12.16.2-linux-x64 /usr/local/node
cd /usr/local/node/bin
./node -v
2.添加到环境变量ln -s /usr/local/node/bin/node /usr/local/bin/node
ln -s /usr/local/node/bin/npm /usr/local/bin/npm
源码编译安装
1.下载安装yum -y install gcc make cmake
wget https://cdn.npm.taobao.org/dist/node/v12.16.2/node-v12.16.2.tar.gz
tar -xzvf node-v12.16.2.tar.gz
mv node-v12.16.2 /usr/local/node
cd /usr/local/node
2.编译./configure``make && make install
./node -v
3.添加到环境变量ln -s /usr/local/node/bin/node /usr/local/bin/node
ln -s /usr/local/node/bin/npm /usr/local/bin/npm
设置npm源
1.查看当前源npm config get registry
2.更换npm源为国内淘宝镜像npm config set registry http://registry.npm.taobao.org/
3.或者更换为国内npm官方镜像npm config set registry http://registry.cnpmjs.org/
4.还原npm源npm config set registry https://registry.npmjs.org/