Difference between composer install and composer update?

Difference between composer install and composer update?

At the end of this post, you will have a clear idea about when to use `composer install` and when to use `composer update`.

Most beginner developers get confused between the usage of the commands composer install and composer update. I also had this confusion in starting and I did some research on it from Google and also discussed my concerns with my seniors. I thought to share the knowledge with all of you hence writing this post.

At the end of this post, you will have a clear idea about when to use composer install and when to use composer update.

composer install

When we execute the composer install command then it reads the composer.lock file and installs dependencies which are mentioned in this file.

If the composer.lock file is not present then it reads the composer.json file and installs the dependencies then creates the composer.lock file.

This command never updates the composer.lock file, it only creates the composer.lock file when the composer.lock file is not present.

composer install command is safe to execute on the production and development environment as it only installs the dependencies and does NOT update the dependencies.

composer update

When we execute the composer update command then it reads the composer.json file and installs dependencies. After installing dependencies it creates/updates the composer.lock file with updated dependencies.

It always reads the composer.json file and not the composer.lock file.

It is NOT recommended to execute the composer update command on the production environment because it updates the dependencies and it may break the functionality. Better do it on the development environment ( development phase ). composer update is mostly used in the 'development phase', to upgrade our project packages according to what we have specified in the composer.json file.

I hope you understood the difference between composer install and composer update. And got a clear idea about when to use composer install and when to use composer update.