1 ---
2 title: npm-update
3 section: 1
4 description: Update packages
5 github_repo: npm/cli
6 github_branch: release/v7
7 github_path: docs/content/commands/npm-update.md
8 redirect_from:
9 - /cli-documentation/v7/cli-commands/npm-update
10 - /cli-documentation/v7/cli-commands/update
11 - /cli-documentation/v7/commands/npm-update
12 - /cli-documentation/v7/commands/update
13 - /cli-documentation/v7/npm-update
14 - /cli-documentation/v7/update
15 - /cli/v7/cli-commands/npm-update
16 - /cli/v7/cli-commands/update
17 - /cli/v7/commands/update
18 - /cli/v7/npm-update
19 - /cli/v7/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 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 ### Example
41
42 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:
43
44 ```json
45 {
46 "dist-tags": { "latest": "1.2.2" },
47 "versions": [
48 "1.2.2",
49 "1.2.1",
50 "1.2.0",
51 "1.1.2",
52 "1.1.1",
53 "1.0.0",
54 "0.4.1",
55 "0.4.0",
56 "0.2.0"
57 ]
58 }
59 ```
60
61 #### Caret Dependencies
62
63 If `app`'s `package.json` contains:
64
65 ```json
66 "dependencies": {
67 "dep1": "^1.1.1"
68 }
69 ```
70
71 Then `npm update` will install `dep1@1.2.2`, because `1.2.2` is `latest` and `1.2.2` satisfies `^1.1.1`.
72
73 #### Tilde Dependencies
74
75 However, if `app`'s `package.json` contains:
76
77 ```json
78 "dependencies": {
79 "dep1": "~1.1.1"
80 }
81 ```
82
83 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`.
84
85 #### Caret Dependencies below 1.0.0
86
87 Suppose `app` has a caret dependency on a version below `1.0.0`, for example:
88
89 ```json
90 "dependencies": {
91 "dep1": "^0.2.0"
92 }
93 ```
94
95 `npm update` will install `dep1@0.2.0`, because there are no other versions which satisfy `^0.2.0`.
96
97 If the dependence were on `^0.4.0`:
98
99 ```json
100 "dependencies": {
101 "dep1": "^0.4.0"
102 }
103 ```
104
105 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`)
106
107 #### Subdependencies
108
109 Suppose your app now also has a dependency on `dep2`
110
111 ```json
112 {
113 "name": "my-app",
114 "dependencies": {
115 "dep1": "^1.0.0",
116 "dep2": "1.0.0"
117 }
118 }
119 ```
120
121 and `dep2` itself depends on this limited range of `dep1`
122
123 ```json
124 {
125 "name": "dep2",
126 "dependencies": {
127 "dep1": "~1.1.1"
128 }
129 }
130 ```
131
132 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`.
133
134 #### Updating Globally-Installed Packages
135
136 `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`.
137
138 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>...]`
139
140 NOTE: If a package has been upgraded to a version newer than `latest`, it will be _downgraded_.
141
142 ### Configuration
143
144 #### `global`
145
146 - Default: false
147 - Type: Boolean
148
149 Operates in "global" mode, so that packages are installed into the `prefix` folder instead of the current working directory. See [folders](/cli/v7/configuring-npm/folders) for more on the differences in behavior.
150
151 - packages are installed into the `{prefix}/lib/node_modules` folder, instead of the current working directory.
152 - bin files are linked to `{prefix}/bin`
153 - man pages are linked to `{prefix}/share/man`
154
155 #### `global-style`
156
157 - Default: false
158 - Type: Boolean
159
160 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.
161
162 #### `legacy-bundling`
163
164 - Default: false
165 - Type: Boolean
166
167 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.
168
169 #### `strict-peer-deps`
170
171 - Default: false
172 - Type: Boolean
173
174 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.
175
176 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.
177
178 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.
179
180 #### `package-lock`
181
182 - Default: true
183 - Type: Boolean
184
185 If set to false, then ignore `package-lock.json` files when installing. This will also prevent _writing_ `package-lock.json` if `save` is true.
186
187 When package package-locks are disabled, automatic pruning of extraneous modules will also be disabled. To remove extraneous modules with package-locks disabled use `npm prune`.
188
189 #### `omit`
190
191 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty.
192 - Type: "dev", "optional", or "peer" (can be set multiple times)
193
194 Dependency types to omit from the installation tree on disk.
195
196 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.
197
198 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
199
200 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
201
202 #### `ignore-scripts`
203
204 - Default: false
205 - Type: Boolean
206
207 If true, npm does not run scripts specified in package.json files.
208
209 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.
210
211 #### `audit`
212
213 - Default: true
214 - Type: Boolean
215
216 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/v7/commands/npm-audit) for details on what is submitted.
217
218 #### `bin-links`
219
220 - Default: true
221 - Type: Boolean
222
223 Tells npm to create symlinks (or `.cmd` shims on Windows) for package executables.
224
225 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.
226
227 #### `fund`
228
229 - Default: true
230 - Type: Boolean
231
232 When "true" displays the message at the end of each `npm install` acknowledging the number of dependencies looking for funding. See [`npm fund`](/cli/v7/commands/npm-fund) for details.
233
234 #### `dry-run`
235
236 - Default: false
237 - Type: Boolean
238
239 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`.
240
241 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
242
243 #### `workspace`
244
245 - Default:
246 - Type: String (can be set multiple times)
247
248 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.
249
250 Valid values for the `workspace` config are either:
251
252 - Workspace names
253 - Path to a workspace directory
254 - Path to a parent workspace directory (will result to selecting all of the nested workspaces)
255
256 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.
257
258 This value is not exported to the environment for child processes.
259
260 #### `workspaces`
261
262 - Default: false
263 - Type: Boolean
264
265 Enable running a command in the context of **all** the configured workspaces.
266
267 This value is not exported to the environment for child processes.
268
269 ### See Also
270
271 - [npm install](/cli/v7/commands/npm-install)
272 - [npm outdated](/cli/v7/commands/npm-outdated)
273 - [npm shrinkwrap](/cli/v7/commands/npm-shrinkwrap)
274 - [npm registry](/cli/v7/using-npm/registry)
275 - [npm folders](/cli/v7/configuring-npm/folders)
276 - [npm ls](/cli/v7/commands/npm-ls)