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