七度&光 2012-09-18 14:07 采纳率: 22.2%
浏览 693
已采纳

Npm 安装 vs 更新-有什么区别?

What is the practical difference between npm install and npm update? When should I use which?

转载于:https://stackoverflow.com/questions/12478679/npm-install-vs-update-whats-the-difference

  • 写回答

4条回答 默认 最新

  • lrony* 2013-11-06 22:26
    关注

    The difference between npm install and npm update handling of package versions specified in package.json:

    {
      "name":          "my-project",
      "version":       "1.0",                             // install   update
      "dependencies":  {                                  // ------------------
        "already-installed-versionless-module":  "*",     // ignores   "1.0" -> "1.1"
        "already-installed-semver-module":       "^1.4.3" // ignores   "1.4.3" -> "1.5.2"
        "already-installed-versioned-module":    "3.4.1"  // ignores   ignores
        "not-yet-installed-versionless-module":  "*",     // installs  installs
        "not-yet-installed-semver-module":       "^4.2.1" // installs  installs
        "not-yet-installed-versioned-module":    "2.7.8"  // installs  installs
      }
    }
    

    Summary: The only big difference is that an already installed module with fuzzy versioning ...

    • gets ignored by npm install
    • gets updated by npm update

    Additionally: install and update by default handle devDependencies differently

    • npm install will install/update devDependencies unless --production flag is added
    • npm update will ignore devDependencies unless --dev flag is added

    Why use npm install at all?

    Because npm install does more when you look besides handling your dependencies in package.json. As you can see in npm install you can ...

    • manually install node-modules
    • set them as global (which puts them in the shell's PATH) using npm install -g <name>
    • install certain versions described by git tags
    • install from a git url
    • force a reinstall with --force
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题