2019-11-05 14:55:08 -05:00
---
2019-11-18 21:01:39 +02:00
section: cli-commands
2019-11-05 14:55:08 -05:00
title: npm-update
description: Update a package
---
2011-11-21 09:48:45 -08:00
2019-11-18 21:01:39 +02:00
# npm-update(1)
2011-11-21 09:48:45 -08:00
2019-11-05 14:55:08 -05:00
## Update a package
2011-11-21 09:48:45 -08:00
2019-11-05 14:55:08 -05:00
### Synopsis
2016-03-29 23:30:51 -07:00
2019-11-05 14:55:08 -05:00
```bash
npm update [-g] [< pkg > ...]
aliases: up, upgrade
```
### Description
2011-11-21 09:48:45 -08:00
This command will update all the packages listed to the latest version
2015-03-06 02:57:32 -06:00
(specified by the `tag` config), respecting semver.
2011-11-21 09:48:45 -08:00
2015-01-17 00:50:09 -08:00
It will also install missing packages. As with all commands that install
packages, the `--dev` flag will cause `devDependencies` to be processed
as well.
2011-11-21 09:48:45 -08:00
2014-09-24 14:41:07 -07:00
If the `-g` flag is specified, this command will update globally installed
packages.
If no package name is specified, all packages in the specified location (global
or local) will be updated.
2013-02-15 10:49:16 -08:00
2015-03-06 02:57:32 -06:00
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.
2016-03-29 23:30:51 -07:00
To get the old behavior, use `npm --depth 9999 update` .
2015-03-06 02:57:32 -06:00
2019-11-18 21:01:39 +02:00
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,
2018-04-20 18:26:37 -07:00
use `npm update --no-save` .
2019-11-05 14:55:08 -05:00
### Example
2015-03-06 02:57:32 -06:00
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.
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:
2019-11-05 14:55:08 -05:00
```json
2015-03-06 02:57:32 -06:00
{
2016-02-22 11:59:14 -08:00
"dist-tags": { "latest": "1.2.2" },
2016-03-29 23:30:51 -07:00
"versions": [
2016-02-22 11:59:14 -08:00
"1.2.2",
"1.2.1",
"1.2.0",
"1.1.2",
"1.1.1",
"1.0.0",
"0.4.1",
"0.4.0",
"0.2.0"
2016-03-29 23:30:51 -07:00
]
2015-03-06 02:57:32 -06:00
}
```
2019-11-05 14:55:08 -05:00
#### Caret Dependencies
2015-03-06 02:57:32 -06:00
If `app` 's `package.json` contains:
2019-11-05 14:55:08 -05:00
```json
2016-02-22 11:59:14 -08:00
"dependencies": {
"dep1": "^1.1.1"
2015-03-06 02:57:32 -06:00
}
```
Then `npm update` will install `dep1@1.2.2` , because `1.2.2` is `latest` and
`1.2.2` satisfies `^1.1.1` .
2019-11-05 14:55:08 -05:00
#### Tilde Dependencies
2015-03-06 02:57:32 -06:00
However, if `app` 's `package.json` contains:
2019-11-05 14:55:08 -05:00
```json
2016-02-22 11:59:14 -08:00
"dependencies": {
"dep1": "~1.1.1"
2015-03-06 02:57:32 -06:00
}
```
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` .
2019-11-05 14:55:08 -05:00
#### Caret Dependencies below 1.0.0
2015-03-06 02:57:32 -06:00
Suppose `app` has a caret dependency on a version below `1.0.0` , for example:
2019-11-05 14:55:08 -05:00
```json
2016-02-22 11:59:14 -08:00
"dependencies": {
"dep1": "^0.2.0"
2015-03-06 02:57:32 -06:00
}
```
`npm update` will install `dep1@0.2.0` , because there are no other
versions which satisfy `^0.2.0` .
If the dependence were on `^0.4.0` :
2019-11-05 14:55:08 -05:00
```json
2016-02-22 11:59:14 -08:00
"dependencies": {
"dep1": "^0.4.0"
2015-03-06 02:57:32 -06:00
}
```
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` )
2019-11-05 14:55:08 -05:00
#### Updating Globally-Installed Packages
2015-03-06 02:57:32 -06:00
2016-02-22 11:59:14 -08:00
`npm update -g` will apply the `update` action to each globally installed
2015-03-06 02:57:32 -06:00
package that is `outdated` -- that is, has a version that is different from
2020-03-19 12:53:27 -04:00
`wanted` .
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>...]`
2015-03-06 02:57:32 -06:00
NOTE: If a package has been upgraded to a version newer than `latest` , it will
be _downgraded_ .
2019-11-05 14:55:08 -05:00
### See Also
2011-11-21 09:48:45 -08:00
2020-10-02 17:52:19 -04:00
* [npm install ](/cli-commands/install )
* [npm outdated ](/cli-commands/outdated )
* [npm shrinkwrap ](/cli-commands/shrinkwrap )
2019-11-05 14:55:08 -05:00
* [npm registry ](/using-npm/registry )
* [npm folders ](/configuring-npm/folders )
2020-10-02 17:52:19 -04:00
* [npm ls ](/cli-commands/ls )