.TH "NPM\-UPDATE" "1" "November 2022" "9.1.1" .SH "NAME" \fBnpm-update\fR .SH Synopsis .SH Description .P This command will update all the packages listed to the latest version .br (specified by the \fBtag\fP config), respecting the semver .br constraints of both your package and its dependencies (if they also require the .br same package)\. .P It will also install missing packages\. .P If the \fB\-g\fP flag is specified, this command will update globally installed .br packages\. .P If no package name is specified, all packages in the specified location (global .br or local) will be updated\. .P Note that by default \fBnpm update\fP will not update the semver values of direct .br dependencies in your project \fBpackage\.json\fP, if you want to also update .br values in \fBpackage\.json\fP you can run: \fBnpm update \-\-save\fP (or add the .br \fBsave=true\fP option to a configuration file .br to make that the default behavior)\. .SH Example .P For the examples below, assume that the current package is \fBapp\fP and it depends .br on dependencies, \fBdep1\fP (\fBdep2\fP, \.\. etc\.)\. The published versions of \fBdep1\fP .br are: .RS 2 .nf { "dist\-tags": { "latest": "1\.2\.2" }, "versions": [ "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" ] } .fi .RE .SS Caret Dependencies .P If \fBapp\fP\|'s \fBpackage\.json\fP contains: .RS 2 .nf "dependencies": { "dep1": "^1\.1\.1" } .fi .RE .P Then \fBnpm update\fP will install \fBdep1@1\.2\.2\fP, because \fB1\.2\.2\fP is \fBlatest\fP and .br \fB1\.2\.2\fP satisfies \fB^1\.1\.1\fP\|\. .SS Tilde Dependencies .P However, if \fBapp\fP\|'s \fBpackage\.json\fP contains: .RS 2 .nf "dependencies": { "dep1": "~1\.1\.1" } .fi .RE .P In this case, running \fBnpm update\fP will install \fBdep1@1\.1\.2\fP\|\. Even though the .br \fBlatest\fP tag points to \fB1\.2\.2\fP, this version do not satisfy \fB~1\.1\.1\fP, which is .br equivalent to \fB>=1\.1\.1 <1\.2\.0\fP\|\. So the highest\-sorting version that satisfies .br \fB~1\.1\.1\fP is used, which is \fB1\.1\.2\fP\|\. .SS Caret Dependencies below 1\.0\.0 .P Suppose \fBapp\fP has a caret dependency on a version below \fB1\.0\.0\fP, for example: .RS 2 .nf "dependencies": { "dep1": "^0\.2\.0" } .fi .RE .P \fBnpm update\fP will install \fBdep1@0\.2\.0\fP, because there are no other .br versions which satisfy \fB^0\.2\.0\fP\|\. .P If the dependence were on \fB^0\.4\.0\fP: .RS 2 .nf "dependencies": { "dep1": "^0\.4\.0" } .fi .RE .P Then \fBnpm update\fP will install \fBdep1@0\.4\.1\fP, because that is the highest\-sorting .br version that satisfies \fB^0\.4\.0\fP (\fB>= 0\.4\.0 <0\.5\.0\fP) .SS Subdependencies .P Suppose your app now also has a dependency on \fBdep2\fP .RS 2 .nf { "name": "my\-app", "dependencies": { "dep1": "^1\.0\.0", "dep2": "1\.0\.0" } } .fi .RE .P and \fBdep2\fP itself depends on this limited range of \fBdep1\fP .RS 2 .nf { "name": "dep2", "dependencies": { "dep1": "~1\.1\.1" } } .fi .RE .P Then \fBnpm update\fP will install \fBdep1@1\.1\.2\fP because that is the highest .br version that \fBdep2\fP allows\. npm will prioritize having a single version .br of \fBdep1\fP in your tree rather than two when that single version can .br satisfy the semver requirements of multiple dependencies in your tree\. .br In this case if you really did need your package to use a newer version .br you would need to use \fBnpm install\fP\|\. .SS Updating Globally\-Installed Packages .P \fBnpm update \-g\fP will apply the \fBupdate\fP action to each globally installed .br package that is \fBoutdated\fP \-\- that is, has a version that is different from .br \fBwanted\fP\|\. .P Note: Globally installed packages are treated as if they are installed with a .br caret semver range specified\. So if you require to update to \fBlatest\fP you may .br need to run \fBnpm install \-g [\.\.\.]\fP .P NOTE: If a package has been upgraded to a version newer than \fBlatest\fP, it will .br be \fIdowngraded\fR\|\. .SH Configuration .SH See Also .RS 1 .IP \(bu 2 npm install .IP \(bu 2 npm outdated .IP \(bu 2 npm shrinkwrap .IP \(bu 2 npm registry .IP \(bu 2 npm folders .IP \(bu 2 npm ls .RE