1 ---
2 title: npm-update
3 section: 1
4 description: Update packages
5 github_repo: npm/cli
6 github_branch: release/v9
7 github_path: docs/lib/content/commands/npm-update.md
8 redirect_from:
9 - /cli-documentation/v9/cli-commands/npm-update
10 - /cli-documentation/v9/cli-commands/update
11 - /cli-documentation/v9/commands/npm-update
12 - /cli-documentation/v9/commands/update
13 - /cli-documentation/v9/npm-update
14 - /cli-documentation/v9/update
15 - /cli/v9/cli-commands/npm-update
16 - /cli/v9/cli-commands/update
17 - /cli/v9/commands/update
18 - /cli/v9/npm-update
19 - /cli/v9/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/v9/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/v9/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 do 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`, because there are no other versions which satisfy `^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/v9/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 #### `strict-peer-deps`
205
206 - Default: false
207 - Type: Boolean
208
209 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.
210
211 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.
212
213 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.
214
215 #### `package-lock`
216
217 - Default: true
218 - Type: Boolean
219
220 If set to false, then ignore `package-lock.json` files when installing. This will also prevent _writing_ `package-lock.json` if `save` is true.
221
222 #### `foreground-scripts`
223
224 - Default: false
225 - Type: Boolean
226
227 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.
228
229 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
230
231 #### `ignore-scripts`
232
233 - Default: false
234 - Type: Boolean
235
236 If true, npm does not run scripts specified in package.json files.
237
238 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.
239
240 #### `audit`
241
242 - Default: true
243 - Type: Boolean
244
245 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/v9/commands/npm-audit) for details on what is submitted.
246
247 #### `bin-links`
248
249 - Default: true
250 - Type: Boolean
251
252 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
253
254 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.
255
256 #### `fund`
257
258 - Default: true
259 - Type: Boolean
260
261 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v9/commands/npm-fund) for details.
262
263 #### `dry-run`
264
265 - Default: false
266 - Type: Boolean
267
268 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`.
269
270 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
271
272 #### `workspace`
273
274 - Default:
275 - Type: String (can be set multiple times)
276
277 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.
278
279 Valid values for the `workspace` config are either:
280
281 - Workspace names
282 - Path to a workspace directory
283 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
284
285 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.
286
287 This value is not exported to the environment for child processes.
288
289 #### `workspaces`
290
291 - Default: null
292 - Type: null or Boolean
293
294 Set to true to run the command in the context of **all** configured workspaces.
295
296 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
297
298 - 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.
299
300 This value is not exported to the environment for child processes.
301
302 #### `include-workspace-root`
303
304 - Default: false
305 - Type: Boolean
306
307 Include the workspace root when workspaces are enabled for a command.
308
309 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.
310
311 This value is not exported to the environment for child processes.
312
313 #### `install-links`
314
315 - Default: false
316 - Type: Boolean
317
318 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.
319
320 ### See Also
321
322 - [npm install](/cli/v9/commands/npm-install)
323 - [npm outdated](/cli/v9/commands/npm-outdated)
324 - [npm shrinkwrap](/cli/v9/commands/npm-shrinkwrap)
325 - [npm registry](/cli/v9/using-npm/registry)
326 - [npm folders](/cli/v9/configuring-npm/folders)
327 - [npm ls](/cli/v9/commands/npm-ls)