npm-update.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <html><head>
  2. <title>npm-update</title>
  3. <style>
  4. body {
  5. background-color: #ffffff;
  6. color: #24292e;
  7. margin: 0;
  8. line-height: 1.5;
  9. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  10. }
  11. #rainbar {
  12. height: 10px;
  13. background-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff);
  14. }
  15. a {
  16. text-decoration: none;
  17. color: #0366d6;
  18. }
  19. a:hover {
  20. text-decoration: underline;
  21. }
  22. pre {
  23. margin: 1em 0px;
  24. padding: 1em;
  25. border: solid 1px #e1e4e8;
  26. border-radius: 6px;
  27. display: block;
  28. overflow: auto;
  29. white-space: pre;
  30. background-color: #f6f8fa;
  31. color: #393a34;
  32. }
  33. code {
  34. font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  35. font-size: 85%;
  36. padding: 0.2em 0.4em;
  37. background-color: #f6f8fa;
  38. color: #393a34;
  39. }
  40. pre > code {
  41. padding: 0;
  42. background-color: inherit;
  43. color: inherit;
  44. }
  45. h1, h2, h3 {
  46. font-weight: 600;
  47. }
  48. #logobar {
  49. background-color: #333333;
  50. margin: 0 auto;
  51. padding: 1em 4em;
  52. }
  53. #logobar .logo {
  54. float: left;
  55. }
  56. #logobar .title {
  57. font-weight: 600;
  58. color: #dddddd;
  59. float: left;
  60. margin: 5px 0 0 1em;
  61. }
  62. #logobar:after {
  63. content: "";
  64. display: block;
  65. clear: both;
  66. }
  67. #content {
  68. margin: 0 auto;
  69. padding: 0 4em;
  70. }
  71. #table_of_contents > h2 {
  72. font-size: 1.17em;
  73. }
  74. #table_of_contents ul:first-child {
  75. border: solid 1px #e1e4e8;
  76. border-radius: 6px;
  77. padding: 1em;
  78. background-color: #f6f8fa;
  79. color: #393a34;
  80. }
  81. #table_of_contents ul {
  82. list-style-type: none;
  83. padding-left: 1.5em;
  84. }
  85. #table_of_contents li {
  86. font-size: 0.9em;
  87. }
  88. #table_of_contents li a {
  89. color: #000000;
  90. }
  91. header.title {
  92. border-bottom: solid 1px #e1e4e8;
  93. }
  94. header.title > h1 {
  95. margin-bottom: 0.25em;
  96. }
  97. header.title > .description {
  98. display: block;
  99. margin-bottom: 0.5em;
  100. line-height: 1;
  101. }
  102. footer#edit {
  103. border-top: solid 1px #e1e4e8;
  104. margin: 3em 0 4em 0;
  105. padding-top: 2em;
  106. }
  107. </style>
  108. </head>
  109. <body>
  110. <div id="banner">
  111. <div id="rainbar"></div>
  112. <div id="logobar">
  113. <svg class="logo" role="img" height="32" width="32" viewBox="0 0 700 700">
  114. <polygon fill="#cb0000" points="0,700 700,700 700,0 0,0"></polygon>
  115. <polygon fill="#ffffff" points="150,550 350,550 350,250 450,250 450,550 550,550 550,150 150,150"></polygon>
  116. </svg>
  117. <div class="title">
  118. npm command-line interface
  119. </div>
  120. </div>
  121. </div>
  122. <section id="content">
  123. <header class="title">
  124. <h1 id="npm-update">npm-update</h1>
  125. <span class="description">Update packages</span>
  126. </header>
  127. <section id="table_of_contents">
  128. <h2 id="table-of-contents">Table of contents</h2>
  129. <div id="_table_of_contents"><ul><li><a href="#synopsis">Synopsis</a></li><li><a href="#description">Description</a></li><li><a href="#example">Example</a></li><ul><li><a href="#caret-dependencies">Caret Dependencies</a></li><li><a href="#tilde-dependencies">Tilde Dependencies</a></li><li><a href="#caret-dependencies-below-100">Caret Dependencies below 1.0.0</a></li><li><a href="#subdependencies">Subdependencies</a></li><li><a href="#updating-globally-installed-packages">Updating Globally-Installed Packages</a></li></ul><li><a href="#configuration">Configuration</a></li><ul><li><a href="#global"><code>global</code></a></li><li><a href="#global-style"><code>global-style</code></a></li><li><a href="#legacy-bundling"><code>legacy-bundling</code></a></li><li><a href="#strict-peer-deps"><code>strict-peer-deps</code></a></li><li><a href="#package-lock"><code>package-lock</code></a></li><li><a href="#omit"><code>omit</code></a></li><li><a href="#ignore-scripts"><code>ignore-scripts</code></a></li><li><a href="#audit"><code>audit</code></a></li><li><a href="#bin-links"><code>bin-links</code></a></li><li><a href="#fund"><code>fund</code></a></li><li><a href="#dry-run"><code>dry-run</code></a></li><li><a href="#workspace"><code>workspace</code></a></li><li><a href="#workspaces"><code>workspaces</code></a></li><li><a href="#include-workspace-root"><code>include-workspace-root</code></a></li></ul><li><a href="#see-also">See Also</a></li></ul></div>
  130. </section>
  131. <div id="_content"><h3 id="synopsis">Synopsis</h3>
  132. <pre lang="bash"><code>npm update [-g] [&lt;pkg&gt;...]
  133. aliases: up, upgrade
  134. </code></pre>
  135. <h3 id="description">Description</h3>
  136. <p>This command will update all the packages listed to the latest version
  137. (specified by the <code>tag</code> config), respecting the semver constraints of
  138. both your package and its dependencies (if they also require the same
  139. package).</p>
  140. <p>It will also install missing packages.</p>
  141. <p>If the <code>-g</code> flag is specified, this command will update globally installed
  142. packages.</p>
  143. <p>If no package name is specified, all packages in the specified location (global
  144. or local) will be updated.</p>
  145. <h3 id="example">Example</h3>
  146. <p>For the examples below, assume that the current package is <code>app</code> and it depends
  147. on dependencies, <code>dep1</code> (<code>dep2</code>, .. etc.). The published versions of <code>dep1</code>
  148. are:</p>
  149. <pre lang="json"><code>{
  150. "dist-tags": { "latest": "1.2.2" },
  151. "versions": [
  152. "1.2.2",
  153. "1.2.1",
  154. "1.2.0",
  155. "1.1.2",
  156. "1.1.1",
  157. "1.0.0",
  158. "0.4.1",
  159. "0.4.0",
  160. "0.2.0"
  161. ]
  162. }
  163. </code></pre>
  164. <h4 id="caret-dependencies">Caret Dependencies</h4>
  165. <p>If <code>app</code>’s <code>package.json</code> contains:</p>
  166. <pre lang="json"><code>"dependencies": {
  167. "dep1": "^1.1.1"
  168. }
  169. </code></pre>
  170. <p>Then <code>npm update</code> will install <code>dep1@1.2.2</code>, because <code>1.2.2</code> is <code>latest</code> and
  171. <code>1.2.2</code> satisfies <code>^1.1.1</code>.</p>
  172. <h4 id="tilde-dependencies">Tilde Dependencies</h4>
  173. <p>However, if <code>app</code>’s <code>package.json</code> contains:</p>
  174. <pre lang="json"><code>"dependencies": {
  175. "dep1": "~1.1.1"
  176. }
  177. </code></pre>
  178. <p>In this case, running <code>npm update</code> will install <code>dep1@1.1.2</code>. Even though the
  179. <code>latest</code> tag points to <code>1.2.2</code>, this version do not satisfy <code>~1.1.1</code>, which is
  180. equivalent to <code>&gt;=1.1.1 &lt;1.2.0</code>. So the highest-sorting version that satisfies
  181. <code>~1.1.1</code> is used, which is <code>1.1.2</code>.</p>
  182. <h4 id="caret-dependencies-below-100">Caret Dependencies below 1.0.0</h4>
  183. <p>Suppose <code>app</code> has a caret dependency on a version below <code>1.0.0</code>, for example:</p>
  184. <pre lang="json"><code>"dependencies": {
  185. "dep1": "^0.2.0"
  186. }
  187. </code></pre>
  188. <p><code>npm update</code> will install <code>dep1@0.2.0</code>, because there are no other
  189. versions which satisfy <code>^0.2.0</code>.</p>
  190. <p>If the dependence were on <code>^0.4.0</code>:</p>
  191. <pre lang="json"><code>"dependencies": {
  192. "dep1": "^0.4.0"
  193. }
  194. </code></pre>
  195. <p>Then <code>npm update</code> will install <code>dep1@0.4.1</code>, because that is the highest-sorting
  196. version that satisfies <code>^0.4.0</code> (<code>&gt;= 0.4.0 &lt;0.5.0</code>)</p>
  197. <h4 id="subdependencies">Subdependencies</h4>
  198. <p>Suppose your app now also has a dependency on <code>dep2</code></p>
  199. <pre lang="json"><code>{
  200. "name": "my-app",
  201. "dependencies": {
  202. "dep1": "^1.0.0",
  203. "dep2": "1.0.0"
  204. }
  205. }
  206. </code></pre>
  207. <p>and <code>dep2</code> itself depends on this limited range of <code>dep1</code></p>
  208. <pre lang="json"><code>{
  209. "name": "dep2",
  210. "dependencies": {
  211. "dep1": "~1.1.1"
  212. }
  213. }
  214. </code></pre>
  215. <p>Then <code>npm update</code> will install <code>dep1@1.1.2</code> because that is the highest
  216. version that <code>dep2</code> allows. npm will prioritize having a single version
  217. of <code>dep1</code> in your tree rather than two when that single version can
  218. satisfy the semver requirements of multiple dependencies in your tree.
  219. In this case if you really did need your package to use a newer version
  220. you would need to use <code>npm install</code>.</p>
  221. <h4 id="updating-globally-installed-packages">Updating Globally-Installed Packages</h4>
  222. <p><code>npm update -g</code> will apply the <code>update</code> action to each globally installed
  223. package that is <code>outdated</code> – that is, has a version that is different from
  224. <code>wanted</code>.</p>
  225. <p>Note: Globally installed packages are treated as if they are installed with a
  226. caret semver range specified. So if you require to update to <code>latest</code> you may
  227. need to run <code>npm install -g [&lt;pkg&gt;...]</code></p>
  228. <p>NOTE: If a package has been upgraded to a version newer than <code>latest</code>, it will
  229. be <em>downgraded</em>.</p>
  230. <h3 id="configuration">Configuration</h3>
  231. <!-- raw HTML omitted -->
  232. <!-- raw HTML omitted -->
  233. <!-- raw HTML omitted -->
  234. <h4 id="global"><code>global</code></h4>
  235. <ul>
  236. <li>Default: false</li>
  237. <li>Type: Boolean</li>
  238. </ul>
  239. <p>Operates in “global” mode, so that packages are installed into the <code>prefix</code>
  240. folder instead of the current working directory. See
  241. <a href="../configuring-npm/folders.html">folders</a> for more on the differences in behavior.</p>
  242. <ul>
  243. <li>packages are installed into the <code>{prefix}/lib/node_modules</code> folder, instead
  244. of the current working directory.</li>
  245. <li>bin files are linked to <code>{prefix}/bin</code></li>
  246. <li>man pages are linked to <code>{prefix}/share/man</code></li>
  247. </ul>
  248. <!-- raw HTML omitted -->
  249. <!-- raw HTML omitted -->
  250. <h4 id="global-style"><code>global-style</code></h4>
  251. <ul>
  252. <li>Default: false</li>
  253. <li>Type: Boolean</li>
  254. </ul>
  255. <p>Causes npm to install the package into your local <code>node_modules</code> folder with
  256. the same layout it uses with the global <code>node_modules</code> folder. Only your
  257. direct dependencies will show in <code>node_modules</code> and everything they depend
  258. on will be flattened in their <code>node_modules</code> folders. This obviously will
  259. eliminate some deduping. If used with <code>legacy-bundling</code>, <code>legacy-bundling</code>
  260. will be preferred.</p>
  261. <!-- raw HTML omitted -->
  262. <!-- raw HTML omitted -->
  263. <h4 id="legacy-bundling"><code>legacy-bundling</code></h4>
  264. <ul>
  265. <li>Default: false</li>
  266. <li>Type: Boolean</li>
  267. </ul>
  268. <p>Causes npm to install the package such that versions of npm prior to 1.4,
  269. such as the one included with node 0.8, can install the package. This
  270. eliminates all automatic deduping. If used with <code>global-style</code> this option
  271. will be preferred.</p>
  272. <!-- raw HTML omitted -->
  273. <!-- raw HTML omitted -->
  274. <h4 id="strict-peer-deps"><code>strict-peer-deps</code></h4>
  275. <ul>
  276. <li>Default: false</li>
  277. <li>Type: Boolean</li>
  278. </ul>
  279. <p>If set to <code>true</code>, and <code>--legacy-peer-deps</code> is not set, then <em>any</em>
  280. conflicting <code>peerDependencies</code> will be treated as an install failure, even
  281. if npm could reasonably guess the appropriate resolution based on non-peer
  282. dependency relationships.</p>
  283. <p>By default, conflicting <code>peerDependencies</code> deep in the dependency graph will
  284. be resolved using the nearest non-peer dependency specification, even if
  285. doing so will result in some packages receiving a peer dependency outside
  286. the range set in their package’s <code>peerDependencies</code> object.</p>
  287. <p>When such and override is performed, a warning is printed, explaining the
  288. conflict and the packages involved. If <code>--strict-peer-deps</code> is set, then
  289. this warning is treated as a failure.</p>
  290. <!-- raw HTML omitted -->
  291. <!-- raw HTML omitted -->
  292. <h4 id="package-lock"><code>package-lock</code></h4>
  293. <ul>
  294. <li>Default: true</li>
  295. <li>Type: Boolean</li>
  296. </ul>
  297. <p>If set to false, then ignore <code>package-lock.json</code> files when installing. This
  298. will also prevent <em>writing</em> <code>package-lock.json</code> if <code>save</code> is true.</p>
  299. <p>When package package-locks are disabled, automatic pruning of extraneous
  300. modules will also be disabled. To remove extraneous modules with
  301. package-locks disabled use <code>npm prune</code>.</p>
  302. <!-- raw HTML omitted -->
  303. <!-- raw HTML omitted -->
  304. <h4 id="omit"><code>omit</code></h4>
  305. <ul>
  306. <li>Default: ‘dev’ if the <code>NODE_ENV</code> environment variable is set to
  307. ‘production’, otherwise empty.</li>
  308. <li>Type: “dev”, “optional”, or “peer” (can be set multiple times)</li>
  309. </ul>
  310. <p>Dependency types to omit from the installation tree on disk.</p>
  311. <p>Note that these dependencies <em>are</em> still resolved and added to the
  312. <code>package-lock.json</code> or <code>npm-shrinkwrap.json</code> file. They are just not
  313. physically installed on disk.</p>
  314. <p>If a package type appears in both the <code>--include</code> and <code>--omit</code> lists, then
  315. it will be included.</p>
  316. <p>If the resulting omit list includes <code>'dev'</code>, then the <code>NODE_ENV</code> environment
  317. variable will be set to <code>'production'</code> for all lifecycle scripts.</p>
  318. <!-- raw HTML omitted -->
  319. <!-- raw HTML omitted -->
  320. <h4 id="ignore-scripts"><code>ignore-scripts</code></h4>
  321. <ul>
  322. <li>Default: false</li>
  323. <li>Type: Boolean</li>
  324. </ul>
  325. <p>If true, npm does not run scripts specified in package.json files.</p>
  326. <p>Note that commands explicitly intended to run a particular script, such as
  327. <code>npm start</code>, <code>npm stop</code>, <code>npm restart</code>, <code>npm test</code>, and <code>npm run-script</code>
  328. will still run their intended script if <code>ignore-scripts</code> is set, but they
  329. will <em>not</em> run any pre- or post-scripts.</p>
  330. <!-- raw HTML omitted -->
  331. <!-- raw HTML omitted -->
  332. <h4 id="audit"><code>audit</code></h4>
  333. <ul>
  334. <li>Default: true</li>
  335. <li>Type: Boolean</li>
  336. </ul>
  337. <p>When “true” submit audit reports alongside the current npm command to the
  338. default registry and all registries configured for scopes. See the
  339. documentation for <a href="../commands/npm-audit.html"><code>npm audit</code></a> for details on what is
  340. submitted.</p>
  341. <!-- raw HTML omitted -->
  342. <!-- raw HTML omitted -->
  343. <h4 id="bin-links"><code>bin-links</code></h4>
  344. <ul>
  345. <li>Default: true</li>
  346. <li>Type: Boolean</li>
  347. </ul>
  348. <p>Tells npm to create symlinks (or <code>.cmd</code> shims on Windows) for package
  349. executables.</p>
  350. <p>Set to false to have it not do this. This can be used to work around the
  351. fact that some file systems don’t support symlinks, even on ostensibly Unix
  352. systems.</p>
  353. <!-- raw HTML omitted -->
  354. <!-- raw HTML omitted -->
  355. <h4 id="fund"><code>fund</code></h4>
  356. <ul>
  357. <li>Default: true</li>
  358. <li>Type: Boolean</li>
  359. </ul>
  360. <p>When “true” displays the message at the end of each <code>npm install</code>
  361. acknowledging the number of dependencies looking for funding. See <a href="../commands/npm-fund.html"><code>npm fund</code></a> for details.</p>
  362. <!-- raw HTML omitted -->
  363. <!-- raw HTML omitted -->
  364. <h4 id="dry-run"><code>dry-run</code></h4>
  365. <ul>
  366. <li>Default: false</li>
  367. <li>Type: Boolean</li>
  368. </ul>
  369. <p>Indicates that you don’t want npm to make any changes and that it should
  370. only report what it would have done. This can be passed into any of the
  371. commands that modify your local installation, eg, <code>install</code>, <code>update</code>,
  372. <code>dedupe</code>, <code>uninstall</code>, as well as <code>pack</code> and <code>publish</code>.</p>
  373. <p>Note: This is NOT honored by other network related commands, eg <code>dist-tags</code>,
  374. <code>owner</code>, etc.</p>
  375. <!-- raw HTML omitted -->
  376. <!-- raw HTML omitted -->
  377. <h4 id="workspace"><code>workspace</code></h4>
  378. <ul>
  379. <li>Default:</li>
  380. <li>Type: String (can be set multiple times)</li>
  381. </ul>
  382. <p>Enable running a command in the context of the configured workspaces of the
  383. current project while filtering by running only the workspaces defined by
  384. this configuration option.</p>
  385. <p>Valid values for the <code>workspace</code> config are either:</p>
  386. <ul>
  387. <li>Workspace names</li>
  388. <li>Path to a workspace directory</li>
  389. <li>Path to a parent workspace directory (will result in selecting all
  390. workspaces within that folder)</li>
  391. </ul>
  392. <p>When set for the <code>npm init</code> command, this may be set to the folder of a
  393. workspace which does not yet exist, to create the folder and set it up as a
  394. brand new workspace within the project.</p>
  395. <p>This value is not exported to the environment for child processes.</p>
  396. <!-- raw HTML omitted -->
  397. <!-- raw HTML omitted -->
  398. <h4 id="workspaces"><code>workspaces</code></h4>
  399. <ul>
  400. <li>Default: null</li>
  401. <li>Type: null or Boolean</li>
  402. </ul>
  403. <p>Set to true to run the command in the context of <strong>all</strong> configured
  404. workspaces.</p>
  405. <p>Explicitly setting this to false will cause commands like <code>install</code> to
  406. ignore workspaces altogether. When not set explicitly:</p>
  407. <ul>
  408. <li>Commands that operate on the <code>node_modules</code> tree (install, update, etc.)
  409. will link workspaces into the <code>node_modules</code> folder. - Commands that do
  410. other things (test, exec, publish, etc.) will operate on the root project,
  411. <em>unless</em> one or more workspaces are specified in the <code>workspace</code> config.</li>
  412. </ul>
  413. <p>This value is not exported to the environment for child processes.</p>
  414. <!-- raw HTML omitted -->
  415. <!-- raw HTML omitted -->
  416. <h4 id="include-workspace-root"><code>include-workspace-root</code></h4>
  417. <ul>
  418. <li>Default: false</li>
  419. <li>Type: Boolean</li>
  420. </ul>
  421. <p>Include the workspace root when workspaces are enabled for a command.</p>
  422. <p>When false, specifying individual workspaces via the <code>workspace</code> config, or
  423. all workspaces via the <code>workspaces</code> flag, will cause npm to operate only on
  424. the specified workspaces, and not on the root project.</p>
  425. <!-- raw HTML omitted -->
  426. <!-- raw HTML omitted -->
  427. <!-- raw HTML omitted -->
  428. <h3 id="see-also">See Also</h3>
  429. <ul>
  430. <li><a href="../commands/npm-install.html">npm install</a></li>
  431. <li><a href="../commands/npm-outdated.html">npm outdated</a></li>
  432. <li><a href="../commands/npm-shrinkwrap.html">npm shrinkwrap</a></li>
  433. <li><a href="../using-npm/registry.html">npm registry</a></li>
  434. <li><a href="../configuring-npm/folders.html">npm folders</a></li>
  435. <li><a href="../commands/npm-ls.html">npm ls</a></li>
  436. </ul>
  437. </div>
  438. <footer id="edit">
  439. <a href="https://github.com/npm/cli/edit/latest/docs/content/commands/npm-update.md">
  440. <svg role="img" viewBox="0 0 16 16" width="16" height="16" fill="currentcolor" style="vertical-align: text-bottom; margin-right: 0.3em;">
  441. <path fill-rule="evenodd" d="M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L10.811 3.75l1.439 1.44 1.263-1.263a.25.25 0 000-.354l-1.086-1.086zM11.189 6.25L9.75 4.81l-6.286 6.287a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.249.249 0 00.108-.064l6.286-6.286z"></path>
  442. </svg>
  443. Edit this page on GitHub
  444. </a>
  445. </footer>
  446. </section>
  447. </body></html>