npm-update.1 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. .TH "NPM\-UPDATE" "1" "August 2021" "" ""
  2. .SH "NAME"
  3. \fBnpm-update\fR \- Update a package
  4. .SS Synopsis
  5. .P
  6. .RS 2
  7. .nf
  8. npm update [\-g] [<pkg>\.\.\.]
  9. aliases: up, upgrade
  10. .fi
  11. .RE
  12. .SS Description
  13. .P
  14. This command will update all the packages listed to the latest version
  15. (specified by the \fBtag\fP config), respecting semver\.
  16. .P
  17. It will also install missing packages\. As with all commands that install
  18. packages, the \fB\-\-dev\fP flag will cause \fBdevDependencies\fP to be processed
  19. as well\.
  20. .P
  21. If the \fB\-g\fP flag is specified, this command will update globally installed
  22. packages\.
  23. .P
  24. If no package name is specified, all packages in the specified location (global
  25. or local) will be updated\.
  26. .P
  27. As of \fBnpm@2\.6\.1\fP, the \fBnpm update\fP will only inspect top\-level packages\.
  28. Prior versions of \fBnpm\fP would also recursively inspect all dependencies\.
  29. To get the old behavior, use \fBnpm \-\-depth 9999 update\fP\|\.
  30. .P
  31. As of \fBnpm@5\.0\.0\fP, the \fBnpm update\fP will change \fBpackage\.json\fP to save the
  32. new version as the minimum required dependency\. To get the old behavior,
  33. use \fBnpm update \-\-no\-save\fP\|\.
  34. .SS Example
  35. .P
  36. IMPORTANT VERSION NOTE: these examples assume \fBnpm@2\.6\.1\fP or later\. For
  37. older versions of \fBnpm\fP, you must specify \fB\-\-depth 0\fP to get the behavior
  38. described below\.
  39. .P
  40. For the examples below, assume that the current package is \fBapp\fP and it depends
  41. on dependencies, \fBdep1\fP (\fBdep2\fP, \.\. etc\.)\. The published versions of \fBdep1\fP are:
  42. .P
  43. .RS 2
  44. .nf
  45. {
  46. "dist\-tags": { "latest": "1\.2\.2" },
  47. "versions": [
  48. "1\.2\.2",
  49. "1\.2\.1",
  50. "1\.2\.0",
  51. "1\.1\.2",
  52. "1\.1\.1",
  53. "1\.0\.0",
  54. "0\.4\.1",
  55. "0\.4\.0",
  56. "0\.2\.0"
  57. ]
  58. }
  59. .fi
  60. .RE
  61. .SS Caret Dependencies
  62. .P
  63. If \fBapp\fP\|'s \fBpackage\.json\fP contains:
  64. .P
  65. .RS 2
  66. .nf
  67. "dependencies": {
  68. "dep1": "^1\.1\.1"
  69. }
  70. .fi
  71. .RE
  72. .P
  73. Then \fBnpm update\fP will install \fBdep1@1\.2\.2\fP, because \fB1\.2\.2\fP is \fBlatest\fP and
  74. \fB1\.2\.2\fP satisfies \fB^1\.1\.1\fP\|\.
  75. .SS Tilde Dependencies
  76. .P
  77. However, if \fBapp\fP\|'s \fBpackage\.json\fP contains:
  78. .P
  79. .RS 2
  80. .nf
  81. "dependencies": {
  82. "dep1": "~1\.1\.1"
  83. }
  84. .fi
  85. .RE
  86. .P
  87. In this case, running \fBnpm update\fP will install \fBdep1@1\.1\.2\fP\|\. Even though the \fBlatest\fP
  88. tag points to \fB1\.2\.2\fP, this version does not satisfy \fB~1\.1\.1\fP, which is equivalent
  89. to \fB>=1\.1\.1 <1\.2\.0\fP\|\. So the highest\-sorting version that satisfies \fB~1\.1\.1\fP is used,
  90. which is \fB1\.1\.2\fP\|\.
  91. .SS Caret Dependencies below 1\.0\.0
  92. .P
  93. Suppose \fBapp\fP has a caret dependency on a version below \fB1\.0\.0\fP, for example:
  94. .P
  95. .RS 2
  96. .nf
  97. "dependencies": {
  98. "dep1": "^0\.2\.0"
  99. }
  100. .fi
  101. .RE
  102. .P
  103. \fBnpm update\fP will install \fBdep1@0\.2\.0\fP, because there are no other
  104. versions which satisfy \fB^0\.2\.0\fP\|\.
  105. .P
  106. If the dependence were on \fB^0\.4\.0\fP:
  107. .P
  108. .RS 2
  109. .nf
  110. "dependencies": {
  111. "dep1": "^0\.4\.0"
  112. }
  113. .fi
  114. .RE
  115. .P
  116. Then \fBnpm update\fP will install \fBdep1@0\.4\.1\fP, because that is the highest\-sorting
  117. version that satisfies \fB^0\.4\.0\fP (\fB>= 0\.4\.0 <0\.5\.0\fP)
  118. .SS Updating Globally\-Installed Packages
  119. .P
  120. \fBnpm update \-g\fP will apply the \fBupdate\fP action to each globally installed
  121. package that is \fBoutdated\fP \-\- that is, has a version that is different from
  122. \fBwanted\fP\|\.
  123. .P
  124. Note: Globally installed packages are treated as if they are installed with a caret semver range specified\. So if you require to update to \fBlatest\fP you may need to run \fBnpm install \-g [<pkg>\.\.\.]\fP
  125. .P
  126. NOTE: If a package has been upgraded to a version newer than \fBlatest\fP, it will
  127. be \fIdowngraded\fR\|\.
  128. .SS See Also
  129. .RS 0
  130. .IP \(bu 2
  131. npm help install
  132. .IP \(bu 2
  133. npm help outdated
  134. .IP \(bu 2
  135. npm help shrinkwrap
  136. .IP \(bu 2
  137. npm help registry
  138. .IP \(bu 2
  139. npm help folders
  140. .IP \(bu 2
  141. npm help ls
  142. .RE