How can I update each dependency in package.json to the latest version?

Better Stack Team
Updated on March 11, 2024

To update each dependency in package.json to the latest version, you can use the npm-check-updates package. Here are the steps:

  1. Install the npm-check-updates package globally by running the following command:
 
npm install -g npm-check-updates
  1. Run the following command to update the package.json file:
 
ncu -u

This command will update all dependencies in package.json to their latest version. It will also update the version numbers in package-lock.json or yarn.lock, depending on which package manager you are using.

  1. Run the following command to install the updated dependencies:
 
npm install

That’s it! Your dependencies should now be updated to the latest version.

Note: This might break some of your APIs. For example, if your package.json has webpack version 1, updating it to the latest version might break your build. Therefore, it’s important to test your application thoroughly after updating your dependencies.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github