一、查看版本
node -v
npm -v
二、npm更新
更新到最新版本:npm install -g npm
更新到指定版本:npm install -g npm@4.2.0
三、node更新
linux环境下:
- 清除node.js的cache(不确定有没有必要)
npm cache clean -f
- 安装工具n ,这个工具是专门用来管理node.js版本的
- 安装命令
npm install -g n
- 出现这样错误信息,在命令后面加上 –force 重新运行
npm ERR! notsup Unsupported platform for n@2.1.8: wanted
{“os”:”!win32”,”arch”:”any”} (current: {“os”:”win32”,”arch”:”x64”})
npm install -g n -f
- 安装最新版本的node.js
安装稳定版本:n stable
安装最新版本:n latest
安装指定版本:n 8.9.4
windows环境:
https://nodejs.org/zh-cn/download/
前往官网下载覆盖安装
四、npm换源
使用npm淘宝源
- 单次下载指定下载源
$ npm install webpack --registry=https://registry.npm.taobao.org
- 永久使用
$ npm config set registry https://registry.npm.taobao.org
- 使用下面命令,可以看到,已经换源了。
npm config list
- 还原npm仓库地址
npm config set registry https://registry.npmjs.org/