Why keep npm updated
Newer npm versions fix bugs and security problems, install packages faster and support new features.
Check the current version
npm -v
You can see the latest version with:
npm view npm version
Update npm on Linux and Ubuntu
npm install -g npm@latest
If you get a permission error (EACCES):
sudo npm install -g npm@latest
A cleaner fix is to set a user-level folder for global packages, or to use nvm (see below), so you do not need sudo.
Update npm on Windows
- Open Command Prompt or PowerShell as Administrator.
- Check the version:
npm -v
- Update:
npm install -g npm@latest
- Close the window, open a new one and check again:
npm -v
Update npm on macOS
With npm:
npm install -g npm@latest
With Homebrew (this updates Node.js, which brings its own npm):
brew update
brew upgrade node
Update Node.js and npm together with nvm
nvm (Node Version Manager) lets you install many Node.js versions and switch between them. Each Node.js version comes with a matching npm.
Install the latest LTS version:
nvm install --lts
nvm use --lts
Install the newest version:
nvm install node
Then check:
node -v
npm -v
Install a specific npm version
npm install -g npm@10.8.2
Troubleshooting
- Command not found after the update: open a new terminal.
- Permission errors: use nvm, or fix the folder owner of the global directory.
- Old version still shows: check
which npm(Linux/macOS) orwhere npm(Windows) for a second install. - Clear the cache if installs fail:
npm cache clean --force.
Quick recap
npm install -g npm@latestupdates npm.- Use nvm to manage Node.js and npm together.