一、安装

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
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐