NpmManager

Summary: Author: 张亚飞 | 阅读时间: 1 minute read | Published: 2016-06-11
Filed under Categories: LinuxTags: Note,

安装 npm

Ubuntu

sudo apt install npm
sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
npm config list
npm config get registry
npm install --registry http://registry.cnpmjs.org express #从中国镜像安装express
npm config set registry https://registry.npm.taobao.org

NpmManage 包管理工具

  • 网络原因导致 npm 软件包 node-sass / gulp-sass 安装失败的处理办法

最后使用 nrm 切换到 cnpm 源安装即可

sudo npm install -g nrm
yafer@pc:~/Workspace/cheyoo/applications/static$ nrm ls

  npm ---- https://registry.npmjs.org/
* cnpm --- http://r.cnpmjs.org/
  taobao - http://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn
  npmMirror  https://skimdb.npmjs.com/registry
yafer@pc:~/Workspace/cheyoo/applications/static$ npm install node-sass
nrm ls
nrm use cnpm
nrm test cnpm

更新 package.json 依赖到最新版本

示例

{
  "name": "myproject",
  "description": "my node project",
  "version": "1.0.0",
  "engines": {
    "node": "0.8.4",
    "npm": "1.1.65"
  },
  "private": true,
  "dependencies": {
    "express": "~3.0.3", // how do I get these bumped to latest?
    "mongodb": "~1.2.5",
    "underscore": "~1.4.2",
    "rjs": "~2.9.0",
    "jade": "~0.27.2",
    "async": "~0.1.22"
  }
}
  • 不依赖插件,通过官方提供的命令

使用命令 npm info express version 检查

npm info express version

简单一点可以将每一个依赖添加 *, 然后执行命令 npm update –save.

"dependencies": {
    "express": "*",
    "mongodb": "*",
    "underscore": "*",
    "rjs": "*",
    "jade": "*",
    "async": "*"
}

更新后:

"dependencies": {
    "express": "~3.2.0",
    "mongodb": "~1.2.14",
    "underscore": "~1.4.4",
    "rjs": "~2.10.0",
    "jade": "~0.29.0",
    "async": "~0.2.7"
}
npm install -g npm-check-updates
$ ncu
 express           4.12.x  →   4.13.x
 multer            ^0.1.8  →   ^1.0.1
 react-bootstrap  ^0.22.6  →  ^0.24.0
 react-a11y        ^0.1.1  →   ^0.2.6
 webpack          ~1.9.10  →  ~1.10.5

Run with -u to upgrade your package.json

参考 * gulp-sass安装失败的解决办法 * 网络原因导致 npm 软件包 node-sass / gulp-sass 安装失败的处理办法

Comments

Cor-Ethan, the beverage → www.iirii.com