windowsnode.jsnpmpackage-managers

How can I update npm on Windows?


I tried this:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

...but it didn't work.

How do I do this on Windows?


Solution

  • Note: The question is specifically asking how to upgrade npm, not Node.js. If you want to update Node.js over a CLI on windows, I recommend running winget upgrade -q NodeJS or use chocolatey for that.

    What method should I choose to update NPM?

    Upgrade with npm-windows-upgrade

    Run PowerShell as Administrator

    Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    npm install -g npm-windows-upgrade
    npm-windows-upgrade
    

    Note: if you run the Node.js installer, it will replace the Node.js version.

    Upgrade with npm

    npm install -g npm
    

    Note: some users still report issues updating npm with npm, but I haven't had that experience with v16+.