Upgrade/Update All NPM Packages to the Latest Versions

Published on August 8, 2021 44 sec read

In this short article, we are going to know how to update all NPM packages to the latest versions.

Table of Contents

  1. Package Installation
  2. Check Available Versions
  3. Upgrade Versions
  4. Check Global Packages

Package Installation

We need to install a package named npm-check-updates globally. It upgrades your package.json dependencies to the latest versions, ignoring specified versions.

Install the package globally:

npm install -g npm-check-updates

Before upgrading all packages, have a look at the package notes:

  • Maintains existing semantic versioning policies, i.e. "express": "^4.0.0" to "express": "^5.0.0".
  • Only modifies package.json file. Run npm install to update your installed packages and package-lock.json.

Check Available Versions

Show any new dependencies for the project in the current directory by typing ncu command:

$ ncu
Checking package.json
[====================] 5/5 100%

 express           4.12.x  →   4.13.x
 multer            ^0.1.8  →   ^1.0.1
 react-bootstrap  ^0.22.6  →  ^0.24.0
 react-a11y        ^0.1.1  →   ^0.2.6
 webpack          ~1.9.10  →  ~1.10.5

Upgrade Versions

Now, run ncu -u to upgrade package.json packages to the latest versions:

$ ncu -u
Upgrading package.json
[====================] 1/1 100%

 express           4.12.x  →   4.13.x

Run npm install to install new versions.

Check Global Packages

To check global packages, run this command:

$ ncu -g
[====================] 5/5 100%

 npm  7.20.3  →  7.20.5

ncu itself cannot upgrade global packages.
Run the following to upgrade all global packages:

npm -g install [email protected]

To know more about this package, have a look at their official repository.

That’s all. Thanks for reading. 🙂

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.
Author

Hey, I'm Md Obydullah. I build open-source projects and write article on Laravel, Linux server, modern JavaScript and more on web development.

Follow