喵-见缝插针 2012-09-18 14:07 采纳率: 0%
浏览 180
已采纳

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条回答 默认 最新

  • 叼花硬汉 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 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿