@reggi/path-to-regexp
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: npm-update |
| 3 | section: 1 |
| 4 | description: Update a package |
| 5 | github_repo: npm/cli |
| 6 | github_branch: release/v6 |
| 7 | github_path: docs/content/commands/npm-update.md |
| 8 | redirect_from: |
| 9 | - /cli-documentation/v6/cli-commands/npm-update |
| 10 | - /cli-documentation/v6/cli-commands/update |
| 11 | - /cli-documentation/v6/commands/npm-update |
| 12 | - /cli-documentation/v6/commands/update |
| 13 | - /cli-documentation/v6/npm-update |
| 14 | - /cli-documentation/v6/update |
| 15 | - /cli/v6/cli-commands/npm-update |
| 16 | - /cli/v6/cli-commands/update |
| 17 | - /cli/v6/commands/update |
| 18 | - /cli/v6/npm-update |
| 19 | - /cli/v6/update |
| 20 | --- |
| 21 | |
| 22 | ### Synopsis |
| 23 | |
| 24 | ```bash |
| 25 | npm update [-g] [<pkg>...] |
| 26 | |
| 27 | aliases: up, upgrade |
| 28 | ``` |
| 29 | |
| 30 | ### Description |
| 31 | |
| 32 | This command will update all the packages listed to the latest version (specified by the `tag` config), respecting semver. |
| 33 | |
| 34 | It will also install missing packages. As with all commands that install packages, the `--dev` flag will cause `devDependencies` to be processed as well. |
| 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 | As of `npm@2.6.1`, the `npm update` will only inspect top-level packages. Prior versions of `npm` would also recursively inspect all dependencies. To get the old behavior, use `npm --depth 9999 update`. |
| 41 | |
| 42 | As of `npm@5.0.0`, the `npm update` will change `package.json` to save the new version as the minimum required dependency. To get the old behavior, use `npm update --no-save`. |
| 43 | |
| 44 | ### Example |
| 45 | |
| 46 | IMPORTANT VERSION NOTE: these examples assume `npm@2.6.1` or later. For older versions of `npm`, you must specify `--depth 0` to get the behavior described below. |
| 47 | |
| 48 | 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: |
| 49 | |
| 50 | ```json |
| 51 | { |
| 52 | "dist-tags": { "latest": "1.2.2" }, |
| 53 | "versions": [ |
| 54 | "1.2.2", |
| 55 | "1.2.1", |
| 56 | "1.2.0", |
| 57 | "1.1.2", |
| 58 | "1.1.1", |
| 59 | "1.0.0", |
| 60 | "0.4.1", |
| 61 | "0.4.0", |
| 62 | "0.2.0" |
| 63 | ] |
| 64 | } |
| 65 | ``` |
| 66 | |
| 67 | #### Caret Dependencies |
| 68 | |
| 69 | If `app`'s `package.json` contains: |
| 70 | |
| 71 | ```json |
| 72 | "dependencies": { |
| 73 | "dep1": "^1.1.1" |
| 74 | } |
| 75 | ``` |
| 76 | |
| 77 | Then `npm update` will install `dep1@1.2.2`, because `1.2.2` is `latest` and `1.2.2` satisfies `^1.1.1`. |
| 78 | |
| 79 | #### Tilde Dependencies |
| 80 | |
| 81 | However, if `app`'s `package.json` contains: |
| 82 | |
| 83 | ```json |
| 84 | "dependencies": { |
| 85 | "dep1": "~1.1.1" |
| 86 | } |
| 87 | ``` |
| 88 | |
| 89 | 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`. |
| 90 | |
| 91 | #### Caret Dependencies below 1.0.0 |
| 92 | |
| 93 | Suppose `app` has a caret dependency on a version below `1.0.0`, for example: |
| 94 | |
| 95 | ```json |
| 96 | "dependencies": { |
| 97 | "dep1": "^0.2.0" |
| 98 | } |
| 99 | ``` |
| 100 | |
| 101 | `npm update` will install `dep1@0.2.0`, because there are no other versions which satisfy `^0.2.0`. |
| 102 | |
| 103 | If the dependence were on `^0.4.0`: |
| 104 | |
| 105 | ```json |
| 106 | "dependencies": { |
| 107 | "dep1": "^0.4.0" |
| 108 | } |
| 109 | ``` |
| 110 | |
| 111 | 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`) |
| 112 | |
| 113 | #### Updating Globally-Installed Packages |
| 114 | |
| 115 | `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`. |
| 116 | |
| 117 | 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>...]` |
| 118 | |
| 119 | NOTE: If a package has been upgraded to a version newer than `latest`, it will be _downgraded_. |
| 120 | |
| 121 | ### See Also |
| 122 | |
| 123 | - [npm install](/cli/v6/commands/npm-install) |
| 124 | - [npm outdated](/cli/v6/commands/npm-outdated) |
| 125 | - [npm shrinkwrap](/cli/v6/commands/npm-shrinkwrap) |
| 126 | - [npm registry](/cli/v6/using-npm/registry) |
| 127 | - [npm folders](/cli/v6/configuring-npm/folders) |
| 128 | - [npm ls](/cli/v6/commands/npm-ls) |