While there is heavy debate surrounding which node.js package manager is best (npm vs yarn vs pnpm), the node package manager holds the default spot. But while users are prompted to install it alongside node.js, they often forget about it soon after. To address this, we'll be showing you how to update npm using several methods.

How to update npm with npm install

The npm install command is officially recommended if you want to try the latest npm version on Linux or macOS.

npm install npm@latest

This will update to the latest version of node package manager. You can also choose a specific version or downgrade to an older version of npm if necessary. Just type its version number after npm:

npm update 9.9.2

How to update npm with npm update

What does npm update do?

The easier way to update npm is by using the package manager itself. Running the npm update command updates the package manager, Node.js, and its modules. In other words, your npm and node.js versions are linked. You can use npm update to update each globally installed package (-g) or all local and global packages.

Updating npm

The npm update command most people will want to use is:

npm update -g

Bear in mind that if a package has been upgraded to a version newer than the one on the latest channel, it will be downgraded.

You can also use npm install -g npm@next to install the next version of node.

How to update npm using nvm

Another valid way to update npm and Node.js is using node version manager (nvm). You can install nvm with:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Then run the command it suggests to start using nvm instantly. Make sure to check the Github for the latest version of the above command.

Updating node and nvm is then as simple as typing:

nvm install node

A useful feature of nvm lets you install different versions of node/npm and switch between them. For example, we could install LTS with nvm install --lts and then switch to it using nvm use --lts.

How to update npm using the n module

You can also update npm using n helper module. This method is outdated and only works on Linux and macOS, which is why it's not at the top of our list. However, it may be worth trying if you're having issues with the other methods. Run these commands:

sudo npm cache clean -f sudo npm install -g nsudo n latest

As with most methods, you don't necessarily need to update to the latest node.js version with the final command. You could instead use n stable or write a specific version number.

Updating npm with the Node.js installer on Windows

If you're using Windows, then updating applications via their dedicated installer will likely be the most familiar to you. This works for npm, too. Just:

  1. Download the latest Node.js Windows installer from the official website.

2. Double-click the executable to run the installation wizard.

3. Choose "Change" and make sure the npm feature is enabled.

4. Press "Next" until the installation is complete.