npm update does not do anything
The npm update --dd
output says why at the end:
...not updating @angular/common because it's currently at the maximum version that matches its specified semver range
Look at this specific package, angular/common
. You have it set to 2.0.0
, which means npm will always fetch that specific version. If you want the package to update, you need to use a semver range. You can view a comprehensive list of semver ranges here, but the most commonly used are probably ~
and ^
.
~
means that the patch version will update. So if you have version ~1.2.1
, it will update to any 1.2.x
, but never to 1.3.0
.
^
updates the minor version, so if you have ^1.2.1
, it will update to any 1.x.x
release, but never to 2.0.0
.
To update, here are the steps:
Running
npm outdated
will allow you to check all the packages that need to be updated. The list will show current, wanted and latest version of each package.Next, run
npm update
which will update all the packages to the latest possible version as defined inpackage.json
. For example, if a certain package inpackage.json
has version ^2.3.1 then this package will not be updated beyond 2.x.x, and if a package has version ~5.3.2 then it will not be updated beyond 5.3.x. (to understand semantic versioning, read this)But what if you want to update to the latest, and the versions of your packages in
package.json
are preventing you from updating as described in step 2 above? Well there are two solutions.a) You can manually update the package versions in
package.json
by changing the versions of your packages to the latest values you like them to be. Although this might work, this is very tedious and error prone. So I do not recommend it.b) You can automatically update the versions of your packages in
package.json
. To do so, you need to install thenpm-check-updates
package (I typically install this package globally) using this command:npm i -g npm-check-updates
. Once this is done, you have to runncu -u
. This will only update the package versions inpackage.json
to the latest version. I recommend this method.Now, after updating the versions of your packages in
package.json
, runnpm update
and your packages will be updated to the latest version.
If npm [-g] outdated
shows outdated packages outside of the semver range (e.g. a major update), the update
command cannot be used to update these packages.
To install the latest version, explicitly specify the package with
npm install [-g] <package>