Open In App

How to Update NPM?

Last Updated : 16 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

NPM (Node Package Manager) is an essential tool for managing JavaScript libraries and packages. It’s commonly used for NodeJS projects to install, update, and manage dependencies. Like other software, NPM also gets updated, which introduces new features, improvements, and bug fixes.

  • NPM can install packages globally (for system-wide use) or locally (specific to a project).
  • You can install packages with simple commands like npm install <package-name>.
  • It helps you to easily manage and install JavaScript libraries and dependencies in your projects.

Why You Should Update NPM

Updating NPM brings several benefits:

  • Security: Fixes vulnerabilities.
  • Bug Fixes: Solves issues and improves stability.
  • New Features: Adds tools that improve productivity.
  • Compatibility: Ensures compatibility with NodeJS and other tools.

How NPM Versions Work

NPM uses a versioning system with three parts: Major.Minor.Patch.

  • Major updates (e.g., 9.0.0) introduce changes that can break compatibility with previous versions.
  • Minor updates (e.g., 8.1.0) add new features but keep everything else compatible.
  • Patch updates (e.g., 8.0.1) fix bugs or minor issues without changing features.

Note: If NPM is not installed on your device check this article to install npm and NodeJS.

Check Your Current NPM Version

Run this command to check your current NPM version:

npm -v

Steps to Update NPM

Now, let's look at how to update NPM on different systems:

1. Updating NPM on Windows

  1. Open Command Prompt as Administrator.
  2. Run the update command:
npm install npm@latest -g

This command will install the latest version of NPM globally, replacing the existing version.

  • -g stands for "global" and ensures that the update applies to your entire system, not just the local project.
  • After the installation completes, check the version again to confirm the update was successful:
npm -v

You should now see the latest version of NPM.

  • After updating NPM, you should also update the packages in your project to make sure they are compatible with the new version of NPM. To update all packages in your project, run the following command in your project directory:
npm update
  • This will update all the dependencies in your package.json file to their latest versions that are compatible with the defined version range.
  • If you want to update a specific package, use:
npm update <package-name>

Common Issues:

  • Permission Errors: Run as Administrator.
  • Corrupted Install: Reinstall NodeJS and NPM if issues persist.
    installing latest npm

2. Updating NPM on macOS

On macOS, open Terminal and run:

npm install npm@latest -g

Best Practice: Use Homebrew for easy updates:

brew install node

3. Updating NPM on Linux

1. If using a PPA (Personal Package Archive), update NodeJS:

Write the following command to install NodeJS and npm.

sudo apt update
sudo apt install nodejs

2. If you have cached data issues, clear the cache:

npm cache clean -f

Then update NPM:

sudo npm install npm@latest -g

cache cleaning and stable install of NPM

Using Pre-Release Versions of NPM

If you want to try the latest features, you can install the pre-release version with:

npm install -g npm@next

This command will install the next(pre-release) version of npm globally on your device.

Conclusion

Regularly updating NPM helps maintain security, stability, and compatibility in your NodeJS projects. Follow the simple steps for your operating system, and ensure you're always using the latest version of NPM.


Next Article

Similar Reads