close

[Solved] How to update all dependencies in package.json to the latest version

Hello Guys, Sometimes we need to update our All dependencies in package.json to the latest version At once. So today in this article we are going to discuss How to update all dependencies in package.json to the latest version? Let’s get started with this article without wasting your time.

How to update all dependencies in package.json to the latest version?

  1. How to update all dependencies in package.json to the latest version

    To update all dependencies in package.json to the latest version you have to run the following command in your terminal: npx npm-check-updates Then you can check which package has an update available. You can run the following command root of your project: npx npm-check-updates -u Then You can run npm install to update all packages at once. Just run this command in your terminal: npm install Now, Your all Dependencies are up to date with the latest versions.

  2. update all dependencies in package.json to the latest version

    To update all dependencies in package.json to the latest version npm has one Package named npm-check-updates. This package has the ability to update all packages in the package.json file at once command. All You need to do is just install this package first. First of all, open your terminal and run the following command: npm install -g npm-check-updates Now, You have installed npm-check-updates package. Then You need to check which package has an update available. You can run following command root of your project: ncu Now, You know which package has an update available. Now, We are ready to update all packages at one command. Just run this command: npm install It will Update all your dependencies in package.json to the latest version at once. To make sure your dependencies are updated to the latest version you can run this command. Now, Your all your dependencies in package.json are updated to the latest version.

Solution 1: Use npm-check-updates

npm has one Package named npm-check-updates. This package has the ability to update all packages in the package.json file at once command. All You need to do is just install this package first. First of all, open your terminal and run the following command.

npm install -g npm-check-updates

If You are npx user then run this command.

npx npm-check-updates

Now, You have installed npm-check-updates package. Then You need to check which package has an update available. You can run following command root of your project.

ncu

OUTPUT.

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

Now, You know which package has an update available. Now, We are ready to update all packages at one command. Just run this command.

npm install

It will Update all your dependencies in package.json to the latest version at once. To make sure your dependencies are updated to the latest version you can run this command.

ncu -u

Now, Your all your dependencies in package.json are updated to the latest version.

Solution 2: For NPX users

If You are using npx then you have to run the following command in your terminal.

npx npm-check-updates

Then you can check which package has an update available. You can run following command root of your project.

npx npm-check-updates -u

Then You can run npm install to update all packages at once. Just run this command in your terminal.

npm install 

Now, Your all Dependencies are up to date with the latest versions.

Solution 3: Run this code

# Install and use the `npm-check-updates` package.
$ npm install -g npm-check-updates

# If you agree, update package.json.
$ npm-check-updates -u

#then delete node_modules folder
rm -rf node_modules

#now you can update all package to latest version
npm install 

Solution 4: Update single package

If You want to update a single package to the latest version you need to run the following command.

npm install yourPackage@latest

Suppose I want to Update prismjs then I should run the following command.

npm install prismjs@latest

Also, You can run the command with –save-dev Which means Package will appear in your devDependencies.

npm install prismjs@latest --save-dev

And now your dependency is updated to the latest version.

Solution 5: Use npm-upgrade

the npm-upgrade package is similar to the npm-check-updates package. You just need to install npm-upgrade package by running the following command.

npm i npm-upgrade

Then run npm-upgrade command at the root of your project.

npm-upgrade

and then the above command will check all packages and it will ask you one by one package for update simply you need to pass yes or no. Just like below.

Update "@angular/common" in package.json from 2.4.8 to 2.4.10? (Use arrow keys)
❯ Yes

And Your all Package will Update with your permission. Thanks.

Conclusion

It’s all About Update Dependancy with one command. Hope We Helped you To Update Your Dependancy. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Leave a Comment