1 ---
2 title: npm-update
3 section: 1
4 description: Update packages
5 github_repo: npm/cli
6 github_branch: release/v10
7 github_path: docs/lib/content/commands/npm-update.md
8 redirect_from:
9 - /cli-documentation/v10/cli-commands/npm-update
10 - /cli-documentation/v10/cli-commands/update
11 - /cli-documentation/v10/commands/npm-update
12 - /cli-documentation/v10/commands/update
13 - /cli-documentation/v10/npm-update
14 - /cli-documentation/v10/update
15 - /cli/v10/cli-commands/npm-update
16 - /cli/v10/cli-commands/update
17 - /cli/v10/commands/update
18 - /cli/v10/npm-update
19 - /cli/v10/update
20 ---
21
22 ### Synopsis
23
24 ```bash
25 npm update [<pkg>...]
26
27 aliases: up, upgrade, udpate
28 ```
29
30 ### Description
31
32 This command will update all the packages listed to the latest version (specified by the [`tag` config](/cli/v10/using-npm/config#tag)), respecting the semver constraints of both your package and its dependencies (if they also require the same package).
33
34 It will also install missing packages.
35
36 If the `-g` flag is specified, this command will update globally installed packages.
37
38 If no package name is specified, all packages in the specified location (global or local) will be updated.
39
40 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/v10/configuring-npm/npmrc) to make that the default behavior).
41
42 ### Example
43
44 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:
45
46 ```json
47 {
48 "dist-tags": { "latest": "1.2.2" },
49 "versions": [
50 "1.2.2",
51 "1.2.1",
52 "1.2.0",
53 "1.1.2",
54 "1.1.1",
55 "1.0.0",
56 "0.4.1",
57 "0.4.0",
58 "0.2.0"
59 ]
60 }
61 ```
62
63 #### Caret Dependencies
64
65 If `app`'s `package.json` contains:
66
67 ```json
68 "dependencies": {
69 "dep1": "^1.1.1"
70 }
71 ```
72
73 Then `npm update` will install `dep1@1.2.2`, because `1.2.2` is `latest` and `1.2.2` satisfies `^1.1.1`.
74
75 #### Tilde Dependencies
76
77 However, if `app`'s `package.json` contains:
78
79 ```json
80 "dependencies": {
81 "dep1": "~1.1.1"
82 }
83 ```
84
85 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`.
86
87 #### Caret Dependencies below 1.0.0
88
89 Suppose `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`.
98
99 If the dependence were on `^0.4.0`:
100
101 ```json
102 "dependencies": {
103 "dep1": "^0.4.0"
104 }
105 ```
106
107 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`)
108
109 #### Subdependencies
110
111 Suppose your app now also has a dependency on `dep2`
112
113 ```json
114 {
115 "name": "my-app",
116 "dependencies": {
117 "dep1": "^1.0.0",
118 "dep2": "1.0.0"
119 }
120 }
121 ```
122
123 and `dep2` itself depends on this limited range of `dep1`
124
125 ```json
126 {
127 "name": "dep2",
128 "dependencies": {
129 "dep1": "~1.1.1"
130 }
131 }
132 ```
133
134 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`.
135
136 #### Updating Globally-Installed Packages
137
138 `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`.
139
140 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>...]`
141
142 NOTE: If a package has been upgraded to a version newer than `latest`, it will be _downgraded_.
143
144 ### Configuration
145
146 #### `save`
147
148 - Default: `true` unless when using `npm update` where it defaults to `false`
149 - Type: Boolean
150
151 Save installed packages to a `package.json` file as dependencies.
152
153 When used with the `npm rm` command, removes the dependency from `package.json`.
154
155 Will also prevent writing to `package-lock.json` if set to `false`.
156
157 #### `global`
158
159 - Default: false
160 - Type: Boolean
161
162 Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v10/configuring-npm/folders) for more on the differences in behavior.
163
164 - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory.
165 - bin files are linked to `{prefix}/bin`
166 - man pages are linked to `{prefix}/share/man`
167
168 #### `install-strategy`
169
170 - Default: "hoisted"
171 - Type: "hoisted", "nested", "shallow", or "linked"
172
173 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.
174
175 #### `legacy-bundling`
176
177 - Default: false
178 - Type: Boolean
179 - DEPRECATED: This option has been deprecated in favor of `--install-strategy=nested`
180
181 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`.
182
183 #### `global-style`
184
185 - Default: false
186 - Type: Boolean
187 - DEPRECATED: This option has been deprecated in favor of `--install-strategy=shallow`
188
189 Only install direct dependencies in the top level `node_modules`, but hoist on deeper dependencies. Sets `--install-strategy=shallow`.
190
191 #### `omit`
192
193 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty.
194 - Type: "dev", "optional", or "peer" (can be set multiple times)
195
196 Dependency types to omit from the installation tree on disk.
197
198 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.
199
200 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
201
202 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
203
204 #### `include`
205
206 - Default:
207 - Type: "prod", "dev", "optional", or "peer" (can be set multiple times)
208
209 Option that allows for defining which types of dependencies to install.
210
211 This is the inverse of `--omit=<type>`.
212
213 Dependency types specified in `--include` will not be omitted, regardless of the order in which omit/include are specified on the command-line.
214
215 #### `strict-peer-deps`
216
217 - Default: false
218 - Type: Boolean
219
220 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.
221
222 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.
223
224 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.
225
226 #### `package-lock`
227
228 - Default: true
229 - Type: Boolean
230
231 If set to false, then ignore `package-lock.json` files when installing. This will also prevent _writing_ `package-lock.json` if `save` is true.
232
233 #### `foreground-scripts`
234
235 - Default: `false` unless when using `npm pack` or `npm publish` where it defaults to `true`
236 - Type: Boolean
237
238 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.
239
240 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
241
242 #### `ignore-scripts`
243
244 - Default: false
245 - Type: Boolean
246
247 If true, npm does not run scripts specified in package.json files.
248
249 Note that commands explicitly intended to run a particular script, such as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script` will still run their intended script if `ignore-scripts` is set, but they will _not_ run any pre- or post-scripts.
250
251 #### `audit`
252
253 - Default: true
254 - Type: Boolean
255
256 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/v10/commands/npm-audit) for details on what is submitted.
257
258 #### `bin-links`
259
260 - Default: true
261 - Type: Boolean
262
263 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
264
265 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.
266
267 #### `fund`
268
269 - Default: true
270 - Type: Boolean
271
272 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v10/commands/npm-fund) for details.
273
274 #### `dry-run`
275
276 - Default: false
277 - Type: Boolean
278
279 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`.
280
281 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
282
283 #### `workspace`
284
285 - Default:
286 - Type: String (can be set multiple times)
287
288 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.
289
290 Valid values for the `workspace` config are either:
291
292 - Workspace names
293 - Path to a workspace directory
294 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
295
296 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.
297
298 This value is not exported to the environment for child processes.
299
300 #### `workspaces`
301
302 - Default: null
303 - Type: null or Boolean
304
305 Set to true to run the command in the context of **all** configured workspaces.
306
307 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
308
309 - 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.
310
311 This value is not exported to the environment for child processes.
312
313 #### `include-workspace-root`
314
315 - Default: false
316 - Type: Boolean
317
318 Include the workspace root when workspaces are enabled for a command.
319
320 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.
321
322 This value is not exported to the environment for child processes.
323
324 #### `install-links`
325
326 - Default: false
327 - Type: Boolean
328
329 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.
330
331 ### See Also
332
333 - [npm install](/cli/v10/commands/npm-install)
334 - [npm outdated](/cli/v10/commands/npm-outdated)
335 - [npm shrinkwrap](/cli/v10/commands/npm-shrinkwrap)
336 - [npm registry](/cli/v10/using-npm/registry)
337 - [npm folders](/cli/v10/configuring-npm/folders)
338 - [npm ls](/cli/v10/commands/npm-ls)