安装node.js
$ curl -sL https://rpm.nodesource.com/setup_10.x | bash -
$ yum install -y nodejs
升级node.js
# node有一个模块叫n,是专门用来管理node.js的版本
$ npm install n -g --registry=https://registry.npm.taobao.org
# 安装新版本
$ n stable
installing : node-v12.18.3
mkdir : /usr/local/n/versions/node/12.18.3
fetch : https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz
installed : v12.18.3 (with npm 6.14.6)
Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"
把旧的连接删除,重新建立软连接
$ rm -f /usr/bin/node
$ ln -s /usr/local/n/versions/node/12.18.3/bin/node /usr/bin/
$ node -v
v12.18.3
$ rm -f /usr/bin/npm
$ ln -s /usr/local/n/versions/node/12.18.3/bin/npm /usr/bin/
$ npm -v
6.14.6
$ rm -f /usr/bin/npx
$ ln -s /usr/local/n/versions/node/12.18.3/bin/npx /usr/bin/
$ npx -v
6.14.6