Updating npm to latest version

Recently I had some trouble updating npm to the latest version on Windows, which was driving me crazy until a StackOverflow thread pointed me in the right direction.  Unfortunately I can’t find the thread again, but as this was just a passing comment and not an answer, I thought it would be worth immortalising it here.

By default, npm is installed alongside node, whereas npm‘s globally installed packages are stored separately in a user-specific directory.  However, the installer puts the node directory before the user-specific directory on the PATH, so it will use the old version instead of the one that you’re attempting to update.

Microsoft wrote a small command line tool to workaround this, called npm-windows-upgrade, which can be installed and run like this…

npm install --global --production npm-windows-upgrade
npm-windows-upgrade --npm-version latest

You can also run the steps manually, if you prefer, full details are on the npm Troubleshooting guide pages, under Try the latest stable version of npm – upgrading on Windows.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.