1 ---
2 title: npm-update
3 section: 1
4 description: Update packages
5 github_repo: npm/cli
6 github_branch: release/v8
7 github_path: docs/lib/content/commands/npm-update.md
8 redirect_from:
9 - /cli-documentation/v8/cli-commands/npm-update
10 - /cli-documentation/v8/cli-commands/update
11 - /cli-documentation/v8/commands/npm-update
12 - /cli-documentation/v8/commands/update
13 - /cli-documentation/v8/npm-update
14 - /cli-documentation/v8/update
15 - /cli/v8/cli-commands/npm-update
16 - /cli/v8/cli-commands/update
17 - /cli/v8/commands/update
18 - /cli/v8/npm-update
19 - /cli/v8/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), 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/v8/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/v8/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 #### `global-style`
169
170 - Default: false
171 - Type: Boolean
172
173 Causes npm to install the package into your local `node_modules` folder with the same layout it uses with the global `node_modules` folder. Only your direct dependencies will show in `node_modules` and everything they depend on will be flattened in their `node_modules` folders. This obviously will eliminate some deduping. If used with `legacy-bundling`, `legacy-bundling` will be preferred.
174
175 #### `legacy-bundling`
176
177 - Default: false
178 - Type: Boolean
179
180 Causes npm to install the package such that versions of npm prior to 1.4, such as the one included with node 0.8, can install the package. This eliminates all automatic deduping. If used with `global-style` this option will be preferred.
181
182 #### `omit`
183
184 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty.
185 - Type: "dev", "optional", or "peer" (can be set multiple times)
186
187 Dependency types to omit from the installation tree on disk.
188
189 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.
190
191 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
192
193 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
194
195 #### `strict-peer-deps`
196
197 - Default: false
198 - Type: Boolean
199
200 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.
201
202 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.
203
204 When such and 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.
205
206 #### `package-lock`
207
208 - Default: true
209 - Type: Boolean
210
211 If set to false, then ignore `package-lock.json` files when installing. This will also prevent _writing_ `package-lock.json` if `save` is true.
212
213 This configuration does not affect `npm ci`.
214
215 #### `foreground-scripts`
216
217 - Default: false
218 - Type: Boolean
219
220 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.
221
222 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
223
224 #### `ignore-scripts`
225
226 - Default: false
227 - Type: Boolean
228
229 If true, npm does not run scripts specified in package.json files.
230
231 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.
232
233 #### `audit`
234
235 - Default: true
236 - Type: Boolean
237
238 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/v8/commands/npm-audit) for details on what is submitted.
239
240 #### `bin-links`
241
242 - Default: true
243 - Type: Boolean
244
245 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
246
247 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.
248
249 #### `fund`
250
251 - Default: true
252 - Type: Boolean
253
254 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v8/commands/npm-fund) for details.
255
256 #### `dry-run`
257
258 - Default: false
259 - Type: Boolean
260
261 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`.
262
263 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
264
265 #### `workspace`
266
267 - Default:
268 - Type: String (can be set multiple times)
269
270 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.
271
272 Valid values for the `workspace` config are either:
273
274 - Workspace names
275 - Path to a workspace directory
276 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
277
278 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.
279
280 This value is not exported to the environment for child processes.
281
282 #### `workspaces`
283
284 - Default: null
285 - Type: null or Boolean
286
287 Set to true to run the command in the context of **all** configured workspaces.
288
289 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
290
291 - 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.
292
293 This value is not exported to the environment for child processes.
294
295 #### `include-workspace-root`
296
297 - Default: false
298 - Type: Boolean
299
300 Include the workspace root when workspaces are enabled for a command.
301
302 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.
303
304 This value is not exported to the environment for child processes.
305
306 #### `install-links`
307
308 - Default: false
309 - Type: Boolean
310
311 When set file: protocol dependencies that exist outside of the project root will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
312
313 ### See Also
314
315 - [npm install](/cli/v8/commands/npm-install)
316 - [npm outdated](/cli/v8/commands/npm-outdated)
317 - [npm shrinkwrap](/cli/v8/commands/npm-shrinkwrap)
318 - [npm registry](/cli/v8/using-npm/registry)
319 - [npm folders](/cli/v8/configuring-npm/folders)
320 - [npm ls](/cli/v8/commands/npm-ls)