DEV Community

Sven Schannak
Sven Schannak

Posted on

Composer - When to use install, update or require

Using composer and other package managers like npm can have a different meaning for their commands to install or update packages. Image the following content of your composer.json and composer.lock:

composer.json

"laravel/framework": "v8.*"
Enter fullscreen mode Exit fullscreen mode

composer.lock

"name": "laravel/framework",
"version": "v8.83.17"
Enter fullscreen mode Exit fullscreen mode

composer install laravel/framework

When you use the install command, composer will install the version from the composer.lock file. For the example this would be v8.83.25.

composer update laravel/framework

Using the update command would install the version as given in the composer.json file. For the example this would be v8.83.26, because it is the latest version for v8 (as today).

composer require laravel/framework

Require will "ignore" the versions from composer.json and composer.lock and will install the newest version available. As today this would be v9.41.0. Also composer.json and composer.lock will be updated.


install -> v8.83.17
update -> v8.83.26
require -> v9.41.0

Top comments (0)