• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2section: cli-commands
3title: npm-update
4description: Update a package
5---
6
7# npm-update(1)
8
9## Update a package
10
11### Synopsis
12
13```bash
14npm update [-g] [<pkg>...]
15
16aliases: up, upgrade
17```
18
19### Description
20
21This command will update all the packages listed to the latest version
22(specified by the `tag` config), respecting semver.
23
24It will also install missing packages. As with all commands that install
25packages, the `--dev` flag will cause `devDependencies` to be processed
26as well.
27
28If the `-g` flag is specified, this command will update globally installed
29packages.
30
31If no package name is specified, all packages in the specified location (global
32or local) will be updated.
33
34As of `npm@2.6.1`, the `npm update` will only inspect top-level packages.
35Prior versions of `npm` would also recursively inspect all dependencies.
36To get the old behavior, use `npm --depth 9999 update`.
37
38As of `npm@5.0.0`, the `npm update` will change `package.json` to save the
39new version as the minimum required dependency. To get the old behavior,
40use `npm update --no-save`.
41
42### Example
43
44IMPORTANT VERSION NOTE: these examples assume `npm@2.6.1` or later.  For
45older versions of `npm`, you must specify `--depth 0` to get the behavior
46described below.
47
48For the examples below, assume that the current package is `app` and it depends
49on dependencies, `dep1` (`dep2`, .. etc.).  The published versions of `dep1` are:
50
51```json
52{
53  "dist-tags": { "latest": "1.2.2" },
54  "versions": [
55    "1.2.2",
56    "1.2.1",
57    "1.2.0",
58    "1.1.2",
59    "1.1.1",
60    "1.0.0",
61    "0.4.1",
62    "0.4.0",
63    "0.2.0"
64  ]
65}
66```
67
68#### Caret Dependencies
69
70If `app`'s `package.json` contains:
71
72```json
73"dependencies": {
74  "dep1": "^1.1.1"
75}
76```
77
78Then `npm update` will install `dep1@1.2.2`, because `1.2.2` is `latest` and
79`1.2.2` satisfies `^1.1.1`.
80
81#### Tilde Dependencies
82
83However, if `app`'s `package.json` contains:
84
85```json
86"dependencies": {
87  "dep1": "~1.1.1"
88}
89```
90
91In this case, running `npm update` will install `dep1@1.1.2`.  Even though the `latest`
92tag points to `1.2.2`, this version does not satisfy `~1.1.1`, which is equivalent
93to `>=1.1.1 <1.2.0`.  So the highest-sorting version that satisfies `~1.1.1` is used,
94which is `1.1.2`.
95
96#### Caret Dependencies below 1.0.0
97
98Suppose `app` has a caret dependency on a version below `1.0.0`, for example:
99
100```json
101"dependencies": {
102  "dep1": "^0.2.0"
103}
104```
105
106`npm update` will install `dep1@0.2.0`, because there are no other
107versions which satisfy `^0.2.0`.
108
109If the dependence were on `^0.4.0`:
110
111```json
112"dependencies": {
113  "dep1": "^0.4.0"
114}
115```
116
117Then `npm update` will install `dep1@0.4.1`, because that is the highest-sorting
118version that satisfies `^0.4.0` (`>= 0.4.0 <0.5.0`)
119
120
121#### Updating Globally-Installed Packages
122
123`npm update -g` will apply the `update` action to each globally installed
124package that is `outdated` -- that is, has a version that is different from
125`wanted`.
126
127Note: 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>...]`
128
129NOTE: If a package has been upgraded to a version newer than `latest`, it will
130be _downgraded_.
131
132
133### See Also
134
135* [npm install](/cli-commands/npm-install)
136* [npm outdated](/cli-commands/npm-outdated)
137* [npm shrinkwrap](/cli-commands/npm-shrinkwrap)
138* [npm registry](/using-npm/registry)
139* [npm folders](/configuring-npm/folders)
140* [npm ls](/cli-commands/npm-ls)
141