125

Command: npm outdated -g

Output:

Package           Current  Wanted  Latest  Location

@angular/cli        1.3.1   1.7.4   7.0.5
create-react-app    1.5.2   1.5.2   2.1.1
eslint              5.6.0   5.9.0   5.9.0
expo-cli            2.2.0   2.3.8   2.3.8
gulp-cli            1.4.0   1.4.0   2.0.1
how-to-npm          2.5.0   2.5.1   2.5.1
mocha               3.5.0   3.5.3   5.2.0
nodemon            1.18.3  1.18.6  1.18.6
now                11.4.6  11.5.2  12.0.1
serve              10.0.1  10.0.2  10.0.2
typescript          2.4.2   2.9.2   3.1.6
yarn                1.9.4  1.12.3  1.12.3

How do I update these outdated packages in npm?

Denilson Sá Maia
  • 47,466
  • 33
  • 109
  • 111
akash
  • 1,437
  • 2
  • 9
  • 12

4 Answers4

185

If you want to update all global packages

npm update -g

If you want to update specific global package

npm update -g <package_name>
Mohit Tilwani
  • 2,716
  • 1
  • 13
  • 13
  • Getting this Error: npm ERR! path /usr/bin/ng npm ERR! code EEXIST npm ERR! Refusing to delete /usr/bin/ng: is outside /usr/lib/node_modules/@angular/cli and not a link npm ERR! File exists: /usr/bin/ng npm ERR! Move it away, and try again – akash Nov 10 '18 at 11:09
  • 1
    If you are using Mac command is sudo npm update -g and if windows open terminal as administrator and then do npm update -g – Mohit Tilwani Nov 10 '18 at 11:19
  • 2
    Just note that there is a gotacha if you use `nvm`. You only list modules from current version, but in your path you might still see old version of a module. This happened for me I had old eslint in old node and couldn't update it. – Nux Jul 11 '20 at 23:26
  • 2
    `npm update -g` is throwing an error on latest, see [issue](https://github.com/npm/cli/issues/1962). – JBallin Oct 26 '20 at 02:48
  • Can we update it to specific version with this command? – meekash55 Mar 17 '21 at 13:47
  • What version does this upgrade the packages to? Where can we set the desired semver version ranges, like `package.json` for local packages? – phil294 Apr 01 '21 at 13:49
  • @meekash55 https://stackoverflow.com/a/67789493/3442232 might answer your question about what versions will/can be updated to, and the relatively limited options for controlling it. – Andrew D. Bond Jun 01 '21 at 13:24
  • @phil294 https://stackoverflow.com/a/67789493/3442232 might answer your question about what versions will/can be updated to, and the relatively limited options for controlling it. – Andrew D. Bond Jun 01 '21 at 13:25
22

To automatically update all global packages to the 'Latest' version:

npx npm-check --global --update-all

That will update all global packages to the 'Latest' version. More information is available about npm-check, including the ability to perform an interactive update, exclude packages, etc.


To instead only update global packages to the 'Wanted' version shown by npm outdated --global (as globally installed packages are treated as if they are installed with a caret semver range specified):

npm update -g

Lastly, if you want to update (install) a package to a version other than 'Latest' or 'Wanted':

npm install --global <pkg>@<version>
Andrew D. Bond
  • 902
  • 1
  • 11
  • 11
  • as of today : `npm ERR! global requires an add or rm option` – dcsan Oct 18 '21 at 05:58
  • @dcsan What's your npm version, and which command from the answer are you running? global still seems to be a listed option in the current documentation. However, some earlier npm versions had a bug with it. All links below. https://docs.npmjs.com/cli/v7/commands/npm-install#global https://docs.npmjs.com/cli/v7/commands/npm-update#global https://github.com/npm/cli/issues/1962 – Andrew D. Bond Oct 18 '21 at 06:18
7

To add to Mohit's answer, if you're using NPM 2.6 or less, there are a couple scripts that are handy in handling the update in that scenario: https://gist.github.com/othiym23/4ac31155da23962afd0e.

You'll need to create the two files described, and run them from the command prompt. This will update all the packages. For a selective update, scroll down the page at the above link to Dylang's comment from October 20, 2014. The comment below from Nov 6, 2014 will hook you up with scripts for a Windows environment.

Looking at long term maintenance, your best solution might be to update NPM first by running:

npm install npm@latest -g

A fairly comprehensive documentation of the processes can be found at https://docs.npmjs.com/updating-packages-downloaded-from-the-registry

Bytech
  • 1,125
  • 7
  • 22
0

This is what I do in Powershell:

(npm outdated -g) -split "\n" `
  | ForEach-Object {$_ -split "\s+" | Select-Object -First 1} `
  | Select-Object -Skip 1 `
  | ForEach-Object { npm install -g -U $_}
Achilles
  • 1,554
  • 1
  • 28
  • 36