1、安装Node
下载文件
其他版本可以在这里进行选择下载:https://registry.npmmirror.com/binary.html?path=node/
[root@localhost ~]$ mkdir -p /usr/local/nodejs
[root@localhost nodejs]$ cd /usr/local/nodejs/
[root@localhost nodejs]$ wget https://npm.taobao.org/mirrors/node/v12.12.0/node-v12.12.0-linux-x64.tar.gz
解压
[root@localhost nodejs]$ tar -xvf node-v12.12.0-linux-x64.tar.gz
配置环境变量
[root@localhost nodejs]$ vim /etc/profile
添加下面内容
[root@localhost nodejs]$ export NODE_HOME=/usr/local/nodejs/node-v12.12.0-linux-x64
[root@localhost nodejs]$ export PATH=$NODE_HOME/bin:$PATH
这里要注意,NODE_HOME 后面的值是自己解压后的目录,保存后退出
安装目录可以通过whereis node
进行查看
更新环境变量
[root@localhost nodejs]$ source /etc/profile
查看安装版本
[root@localhost nodejs]$ node -v
v12.12.0
[root@localhost nodejs]$ npm -v
6.11.3
可以显示版本则安装成功
其他设置
设置npm镜像源
[root@localhost nodejs]$ npm get registry
https://registry.npmjs.org/
[root@localhost nodejs]$ npm config set registry http://registry.npm.taobao.org/
[root@localhost nodejs]$ npm config set sass-binary-site https://npm.taobao.org/mirrors/node-sass
[root@localhost nodejs]$ npm get registry
http://registry.npm.taobao.org/