DEV Community

Cover image for Composer update Vs Composer Install
Ajay Yadav
Ajay Yadav

Posted on • Edited on

Composer update Vs Composer Install

Composer update and composer install, These two commands are very useful when you develop any project with composer packages. So Lets figure this out how these two are different from each other🤔.

And Make sure you Like and subscribe 😉👍👍.

Composer Install

When you run Composer install in your terminal it reads the composer.lock file and install dependencies which are mentioned in this file.
But what if the composer.lock file does not exists. So, In this case it reads the composer.json file and install the dependencies then creates the composer.lock file.

When to run composer install

In production you need only those dependencies which you have used in development phase, And those dependencies can be found with their exact version in composer.lock file. So this command is mainly used in production.
you can use it in development phase also.😎

Composer update

When you run composer update command it simply process the composer.json file and install dependencies, And creates the composer.lock file with updated dependencies.

It does not process the composer.lock file , but it updates the dependencies version in the lock file.

When to run composer update

composer update command should be used only in development phase of the project. Because It updates the dependencies and also update the composer.lock file.
If you run this command in production it can break your code, because it'll update the dependencies which is not good in production because version may change 🤷‍♂️.

Top comments (2)

Collapse
 
realtebo profile image
Mirko Tebaldi

What is composer upgrade doing, instead of composer update ?

Collapse
 
eduardonwa profile image
Eduardo Cookie Lifter • Edited

How can you check for the PHP version utilized by Composer in order to execute these tasks, on those dependencies? How can you update the PHP version to be higher or lower?