25

I'm following steps from updating global packages, so I executed npm outdated -g --depth=0 and got:

Package     Current  Wanted  Latest  Location
typescript    2.2.2   2.2.2   2.4.1

Then, I executed npm update -g, but I still got the same output from npm outdated -g --depth=0.

Executing npm list -g --depth=0 also confirms that the typescript package has not been updated to 2.4.1:

+-- bower@1.8.0
+-- gulp@3.9.1
+-- typescript@2.2.2
`-- typings@2.1.1

What am I missing?

kiewic
  • 15,852
  • 13
  • 78
  • 101
  • What version of npm are you using? Versions before 2.6.1 cannot update all globally. You can however update them one by one by doing `npm update -g ` – Tikkes Jul 13 '17 at 07:45
  • My npm version is 3.10.10 – kiewic Jul 13 '17 at 07:47
  • Official ref https://docs.npmjs.com/getting-started/updating-global-packages – Khurshid Ansari Sep 05 '18 at 10:27
  • 1
    Possible duplicate of [How to update TypeScript to latest version with npm?](https://stackoverflow.com/questions/39677437/how-to-update-typescript-to-latest-version-with-npm) – Liam Jul 16 '19 at 07:41

4 Answers4

18

You will have to either use this script or do them one by one it seems.

This global update is a known breaking point. Here is the reference to this issue. They seem to have closed it without addressing the issue

Tikkes
  • 4,599
  • 4
  • 36
  • 62
  • 3
    Got it. It seems the scripts simply does `npm -g install ` for each package. So I typed that on the Windows console and it updated each package to its latest version. Thank you! – kiewic Jul 13 '17 at 08:05
9

You can also install specific version:

npm install -g typescript@2.4.1
Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52
3

As of now, there is no one simple command that does this.

You can use the following steps instead to find outdated packages and update them one by one.

  1. Determining which global packages need updating: To see which global packages need to be updated, on the command line, run:

    npm outdated -g --depth=0
    
  2. Updating a single global package: To update a single global package, on the command line, run:

    npm update -g <package_name>
    
Sapnesh Naik
  • 11,011
  • 7
  • 63
  • 98
2

To automatically update all global packages to the 'Latest' version in a single command:

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.


Conversely, npm update -g only updates 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.


Lastly, if you happen to 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