1 ---
2 title: npm-update
3 section: 1
4 description: Update packages
5 github_repo: npm/cli
6 github_branch: latest
7 github_path: docs/lib/content/commands/npm-update.md
8 redirect_from:
9 - /cli-commands/npm-update
10 - /cli-commands/update
11 - /cli-documentation/cli-commands/npm-update
12 - /cli-documentation/cli-commands/update
13 - /cli-documentation/commands/npm-update
14 - /cli-documentation/commands/update
15 - /cli-documentation/npm-update
16 - /cli-documentation/update
17 - /cli-documentation/v11/cli-commands/npm-update
18 - /cli-documentation/v11/cli-commands/update
19 - /cli-documentation/v11/commands/npm-update
20 - /cli-documentation/v11/commands/update
21 - /cli-documentation/v11/npm-update
22 - /cli-documentation/v11/update
23 - /cli/cli-commands/npm-update
24 - /cli/cli-commands/update
25 - /cli/commands/npm-update
26 - /cli/commands/update
27 - /cli/npm-update
28 - /cli/update
29 - /cli/v11/cli-commands/npm-update
30 - /cli/v11/cli-commands/update
31 - /cli/v11/commands/update
32 - /cli/v11/npm-update
33 - /cli/v11/update
34 - /commands/npm-update
35 - /commands/update
36 ---
37
38 ### Synopsis
39
40 ```bash
41 npm update [<pkg>...]
42
43 aliases: up, upgrade, udpate
44 ```
45
46 ### Description
47
48 This command will update all the packages listed to the latest version (specified by the [`tag` config](/cli/v11/using-npm/config#tag)), respecting the semver constraints of both your package and its dependencies (if they also require the same package).
49
50 It will also install missing packages.
51
52 If the `-g` flag is specified, this command will update globally installed packages.
53
54 If no package name is specified, all packages in the specified location (global or local) will be updated.
55
56 Note that by default `npm update` will not update the semver values of direct dependencies in your project `package.json`. If you want to also update values in `package.json` you can run: `npm update --save` (or add the `save=true` option to a [configuration file](/cli/v11/configuring-npm/npmrc) to make that the default behavior).
57
58 ### Example
59
60 For the examples below, assume that the current package is `app` and it depends on dependencies, `dep1` (`dep2`, .. etc.). The published versions of `dep1` are:
61
62 ```json
63 {
64 "dist-tags": { "latest": "1.2.2" },
65 "versions": [
66 "1.2.2",
67 "1.2.1",
68 "1.2.0",
69 "1.1.2",
70 "1.1.1",
71 "1.0.0",
72 "0.4.1",
73 "0.4.0",
74 "0.2.0"
75 ]
76 }
77 ```
78
79 #### Caret Dependencies
80
81 If `app`'s `package.json` contains:
82
83 ```json
84 "dependencies": {
85 "dep1": "^1.1.1"
86 }
87 ```
88
89 Then `npm update` will install `dep1@1.2.2`, because `1.2.2` is `latest` and `1.2.2` satisfies `^1.1.1`.
90
91 #### Tilde Dependencies
92
93 However, if `app`'s `package.json` contains:
94
95 ```json
96 "dependencies": {
97 "dep1": "~1.1.1"
98 }
99 ```
100
101 In this case, running `npm update` will install `dep1@1.1.2`. Even though the `latest` tag points to `1.2.2`, this version does not satisfy `~1.1.1`, which is equivalent to `>=1.1.1 <1.2.0`. So the highest-sorting version that satisfies `~1.1.1` is used, which is `1.1.2`.
102
103 #### Caret Dependencies below 1.0.0
104
105 Suppose `app` has a caret dependency on a version below `1.0.0`, for example:
106
107 ```json
108 "dependencies": {
109 "dep1": "^0.2.0"
110 }
111 ```
112
113 `npm update` will install `dep1@0.2.0`.
114
115 If the dependence were on `^0.4.0`:
116
117 ```json
118 "dependencies": {
119 "dep1": "^0.4.0"
120 }
121 ```
122
123 Then `npm update` will install `dep1@0.4.1`, because that is the highest-sorting version that satisfies `^0.4.0` (`>= 0.4.0 <0.5.0`)
124
125 #### Subdependencies
126
127 Suppose your app now also has a dependency on `dep2`
128
129 ```json
130 {
131 "name": "my-app",
132 "dependencies": {
133 "dep1": "^1.0.0",
134 "dep2": "1.0.0"
135 }
136 }
137 ```
138
139 and `dep2` itself depends on this limited range of `dep1`
140
141 ```json
142 {
143 "name": "dep2",
144 "dependencies": {
145 "dep1": "~1.1.1"
146 }
147 }
148 ```
149
150 Then `npm update` will install `dep1@1.1.2` because that is the highest version that `dep2` allows. npm will prioritize having a single version of `dep1` in your tree rather than two when that single version can satisfy the semver requirements of multiple dependencies in your tree. In this case if you really did need your package to use a newer version you would need to use `npm install`.
151
152 #### Updating Globally-Installed Packages
153
154 `npm update -g` will apply the `update` action to each globally installed package that is `outdated` -- that is, has a version that is different from `wanted`.
155
156 Note: Globally installed packages are treated as if they are installed with a caret semver range specified. So if you require to update to `latest` you may need to run `npm install -g [<pkg>...]`
157
158 NOTE: If a package has been upgraded to a version newer than `latest`, it will be _downgraded_.
159
160 ### Configuration
161
162 #### `save`
163
164 - Default: `true` unless when using `npm update` where it defaults to `false`
165 - Type: Boolean
166
167 Save installed packages to a `package.json` file as dependencies.
168
169 When used with the `npm rm` command, removes the dependency from `package.json`.
170
171 Will also prevent writing to `package-lock.json` if set to `false`.
172
173 #### `global`
174
175 - Default: false
176 - Type: Boolean
177
178 Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v11/configuring-npm/folders) for more on the differences in behavior.
179
180 - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory.
181 - bin files are linked to `{prefix}/bin`
182 - man pages are linked to `{prefix}/share/man`
183
184 #### `install-strategy`
185
186 - Default: "hoisted"
187 - Type: "hoisted", "nested", "shallow", or "linked"
188
189 Sets the strategy for installing packages in node_modules. hoisted (default): Install non-duplicated in top-level, and duplicated as necessary within directory structure. nested: (formerly --legacy-bundling) install in place, no hoisting. shallow (formerly --global-style) only install direct deps at top-level. linked: (experimental) install in node_modules/.store, link in place, unhoisted.
190
191 #### `legacy-bundling`
192
193 - Default: false
194 - Type: Boolean
195 - DEPRECATED: This option has been deprecated in favor of `--install-strategy=nested`
196
197 Instead of hoisting package installs in `node_modules`, install packages in the same manner that they are depended on. This may cause very deep directory structures and duplicate package installs as there is no de-duplicating. Sets `--install-strategy=nested`.
198
199 #### `global-style`
200
201 - Default: false
202 - Type: Boolean
203 - DEPRECATED: This option has been deprecated in favor of `--install-strategy=shallow`
204
205 Only install direct dependencies in the top level `node_modules`, but hoist on deeper dependencies. Sets `--install-strategy=shallow`.
206
207 #### `omit`
208
209 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production'; otherwise, empty.
210 - Type: "dev", "optional", or "peer" (can be set multiple times)
211
212 Dependency types to omit from the installation tree on disk.
213
214 Note that these dependencies _are_ still resolved and added to the `package-lock.json` or `npm-shrinkwrap.json` file. They are just not physically installed on disk.
215
216 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
217
218 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
219
220 #### `include`
221
222 - Default:
223 - Type: "prod", "dev", "optional", or "peer" (can be set multiple times)
224
225 Option that allows for defining which types of dependencies to install.
226
227 This is the inverse of `--omit=<type>`.
228
229 Dependency types specified in `--include` will not be omitted, regardless of the order in which omit/include are specified on the command-line.
230
231 #### `strict-peer-deps`
232
233 - Default: false
234 - Type: Boolean
235
236 If set to `true`, and `--legacy-peer-deps` is not set, then _any_ conflicting `peerDependencies` will be treated as an install failure, even if npm could reasonably guess the appropriate resolution based on non-peer dependency relationships.
237
238 By default, conflicting `peerDependencies` deep in the dependency graph will be resolved using the nearest non-peer dependency specification, even if doing so will result in some packages receiving a peer dependency outside the range set in their package's `peerDependencies` object.
239
240 When such an override is performed, a warning is printed, explaining the conflict and the packages involved. If `--strict-peer-deps` is set, then this warning is treated as a failure.
241
242 #### `package-lock`
243
244 - Default: true
245 - Type: Boolean
246
247 If set to false, then ignore `package-lock.json` files when installing. This will also prevent _writing_ `package-lock.json` if `save` is true.
248
249 #### `foreground-scripts`
250
251 - Default: `false` unless when using `npm pack` or `npm publish` where it defaults to `true`
252 - Type: Boolean
253
254 Run all build scripts (ie, `preinstall`, `install`, and `postinstall`) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process.
255
256 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
257
258 #### `ignore-scripts`
259
260 - Default: false
261 - Type: Boolean
262
263 If true, npm does not run scripts specified in package.json files.
264
265 Note that commands explicitly intended to run a particular script, such as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run` will still run their intended script if `ignore-scripts` is set, but they will _not_ run any pre- or post-scripts.
266
267 #### `audit`
268
269 - Default: true
270 - Type: Boolean
271
272 When "true" submit audit reports alongside the current npm command to the default registry and all registries configured for scopes. See the documentation for [`npm audit`](/cli/v11/commands/npm-audit) for details on what is submitted.
273
274 #### `before`
275
276 - Default: null
277 - Type: null or Date
278
279 If passed to `npm install`, will rebuild the npm tree such that only versions that were available **on or before** the given date are installed. If there are no versions available for the current set of dependencies, the command will error.
280
281 If the requested version is a `dist-tag` and the given tag does not pass the `--before` filter, the most recent version less than or equal to that tag will be used. For example, `foo@latest` might install `foo@1.2` even though `latest` is `2.0`.
282
283 #### `bin-links`
284
285 - Default: true
286 - Type: Boolean
287
288 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
289
290 Set to false to have it not do this. This can be used to work around the fact that some file systems don't support symlinks, even on ostensibly Unix systems.
291
292 #### `fund`
293
294 - Default: true
295 - Type: Boolean
296
297 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v11/commands/npm-fund) for details.
298
299 #### `dry-run`
300
301 - Default: false
302 - Type: Boolean
303
304 Indicates that you don't want npm to make any changes and that it should only report what it would have done. This can be passed into any of the commands that modify your local installation, eg, `install`, `update`, `dedupe`, `uninstall`, as well as `pack` and `publish`.
305
306 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
307
308 #### `workspace`
309
310 - Default:
311 - Type: String (can be set multiple times)
312
313 Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
314
315 Valid values for the `workspace` config are either:
316
317 - Workspace names
318 - Path to a workspace directory
319 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
320
321 When set for the `npm init` command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
322
323 This value is not exported to the environment for child processes.
324
325 #### `workspaces`
326
327 - Default: null
328 - Type: null or Boolean
329
330 Set to true to run the command in the context of **all** configured workspaces.
331
332 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
333
334 - Commands that operate on the `node_modules` tree (install, update, etc.) will link workspaces into the `node_modules` folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, _unless_ one or more workspaces are specified in the `workspace` config.
335
336 This value is not exported to the environment for child processes.
337
338 #### `include-workspace-root`
339
340 - Default: false
341 - Type: Boolean
342
343 Include the workspace root when workspaces are enabled for a command.
344
345 When false, specifying individual workspaces via the `workspace` config, or all workspaces via the `workspaces` flag, will cause npm to operate only on the specified workspaces, and not on the root project.
346
347 This value is not exported to the environment for child processes.
348
349 #### `install-links`
350
351 - Default: false
352 - Type: Boolean
353
354 When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
355
356 ### See Also
357
358 - [npm install](/cli/v11/commands/npm-install)
359 - [npm outdated](/cli/v11/commands/npm-outdated)
360 - [npm shrinkwrap](/cli/v11/commands/npm-shrinkwrap)
361 - [npm registry](/cli/v11/using-npm/registry)
362 - [npm folders](/cli/v11/configuring-npm/folders)
363 - [npm ls](/cli/v11/commands/npm-ls)