安装node.js

  1. $ curl -sL https://rpm.nodesource.com/setup_10.x | bash -
  2. $ yum install -y nodejs

升级node.js

  1. # node有一个模块叫n,是专门用来管理node.js的版本
  2. $ npm install n -g --registry=https://registry.npm.taobao.org
  3. # 安装新版本
  4. $ n stable
  5. installing : node-v12.18.3
  6. mkdir : /usr/local/n/versions/node/12.18.3
  7. fetch : https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz
  8. installed : v12.18.3 (with npm 6.14.6)
  9. Note: the node command changed location and the old location may be remembered in your current shell.
  10. old : /usr/bin/node
  11. new : /usr/local/bin/node
  12. To reset the command location hash either start a new shell, or execute PATH="$PATH"

把旧的连接删除,重新建立软连接

  1. $ rm -f /usr/bin/node
  2. $ ln -s /usr/local/n/versions/node/12.18.3/bin/node /usr/bin/
  3. $ node -v
  4. v12.18.3
  5. $ rm -f /usr/bin/npm
  6. $ ln -s /usr/local/n/versions/node/12.18.3/bin/npm /usr/bin/
  7. $ npm -v
  8. 6.14.6
  9. $ rm -f /usr/bin/npx
  10. $ ln -s /usr/local/n/versions/node/12.18.3/bin/npx /usr/bin/
  11. $ npx -v
  12. 6.14.6