We know that Composer is one of the main dependency management tools for our project. It is used to install/update third-party libraries or packages in our project, so to perform all these, Composer has two main commands as below:

1. Composer install
2. Composer update

Composer install:

Definition : This is command which is used to install all the dependencies or exact versions of dependencies added/listed in the composer.lock file.
When we run this command on the terminal, it installs the exact versions of dependencies that are listed in the composer.lock file. If the composer.lock file is not found or does not exist, then it reads the composer.json file and installs all the dependencies in it.

Use:
– While creating a clone of the project, creating a new project, or deploying to production.
– Ensuring that everyone is using the same versions of dependencies.

Example:
– Suppose composer.lock file contains Laravel 9.2.1.
– When we run the composer install command, then it installs the exact same Laravel 9.2.1 version.


Composer update:

Definition: It is the command that is used to update the dependencies with their latest versions.
When we run this command on the terminal, it reads the composer.json file and finds the latest versions of the libraries/packages and updates it accordingly, as well as updating it in the composer.lock file.

Use:
– When updating dependencies to the latest versions (only in development).

Example:
– It updates composer.lock with new versions.
– If composer.json has “laravel/framework”: “^9.0,” it means Laravel 9.0+ is allowed.
– Running composer update will fetch the latest compatible version, e.g., Laravel 9.5.0.

Summary

Use composer install: Reads composer.lock and installs exactly what’s listed. when setting up a project or deploying to production.
Use composer update: Updates the dependencies listed in composer.json, and rewrites composer.lock. It’s used when you want to upgrade packages.