Learn TypeScript 3 by Building Web Applications
上QQ阅读APP看书,第一时间看更新

Windows

On Windows, updating npm is trickier. The issue on Windows is that npm is installed along with Node.js and if you simply try the same approach as for Linux, the new version of npm that you download will always be shadowed by the one coming with node itself. This is due to the order of the entries in your PATH environment variables.

One workaround consists in changing the order of the path entries. Another one is to avoid installing npm when you install node. This lets you install and upgrade npm separately. That also comes with its hassles, though.

Instead, here's a simple solution, using the npm-windows-upgrade (https://github.com/felixrieseberg/npm-windows-upgrade) utility. To use it, open up a Windows shell (that is, cmd.exe) as administrator then execute the following commands:

  • npm install -g npm-windows-upgrade
  • npm-windows-upgrade

You'll be asked to select the version of npm that you want to install. In the proposed list, select a version that is greater than and equal to 6.4.1. Once the upgrade is completed, you should be able to use the new npm version directly! If you're curious about what changed in the npm cli, check out the official release notes: https://github.com/npm/cli/releases.

Note that there are other solutions such as nvm-windows (https://github.com/coreybutler/nvm-windows) that we won't be covering here.