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