一、安装
sudo apt-get install nodejs
sudo apt-get install npm
二、查看是否安装成功及版本
node -v
npm -v
三、升级
sudo npm install -g n
sudo n stable # latest #(升级node.js到最新版) stable #(升级node.js到最新稳定版)
node -v
npm -v
我的输出
searchstar@searchstar-mint19:~$ sudo n stable
installing : node-v12.16.1
mkdir : /usr/local/n/versions/node/12.16.1
fetch : https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz
installed : v12.16.1 (with npm 6.13.4)
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"
这里就很良心地提示了要重启终端或者执行
PATH="$PATH"
四、npm镜像替换为淘宝镜像
#得到原本的镜像地址
npm get registry
#设成淘宝的
npm config set registry http://registry.npm.taobao.org/
#换成原来的
npm config set registry https://registry.npmjs.org/
五、卸载
sudo npm uninstall npm -g
sudo apt-get remove nodejs