Skip to content

/compare/composer/composer-install-vs-composer-update

composer install vs composer update: differences and when to use each

The commands on this page have not been executed by our verification runner yet.updated
tool
Composer
compares
composer install vs composer update

composer install installs exactly the versions recorded in composer.lock, so every machine gets the same code; it only resolves dependencies itself when no lock file exists. composer update ignores the locked versions, resolves the constraints in composer.json again, installs the newest versions they allow and rewrites composer.lock. Run install in CI, Docker builds and after cloning; run update (ideally for named packages) when you want to upgrade.

Side by side

Criterioncomposer installcomposer update
Readscomposer.lock (composer.json only if no lock)composer.json
Writes composer.lockOnly when it did not existAlways
Changes versionsNoYes, within the constraints
Same result on every machineYesNo: depends on when it runs
ScopeWhole projectWhole project, or named packages (composer update vendor/pkg)
SpeedFaster: no dependency resolutionSlower: runs the solver
Typical useCI, deployments, fresh clonesUpgrading dependencies, after editing composer.json

Commands

bash
composer install                              # reproducible install from composer.lock
composer install --no-dev --optimize-autoloader   # production deployment
composer update vendor/package                # upgrade one package (and keep the rest)
composer update vendor/package -W             # also let its dependencies move
composer update --dry-run                     # show what would change
composer outdated --direct                    # list direct dependencies with newer releases

Commit composer.lock for applications. For libraries the lock file is not used by projects that depend on them; many libraries still commit it so their own CI is reproducible.

Which one to use

  • Fresh clone, CI, Docker image, deployment: composer install, with --no-dev --optimize-autoloader for production. It never changes versions, so what was tested is what ships.
  • Adding a package: composer require vendor/pkg, which edits composer.json and updates only what the new package needs.
  • Upgrading one package: composer update vendor/pkg, adding -w or -W when its dependencies must move too.
  • Routine upgrades: composer outdated --direct to see what is behind, then update a few packages at a time and run the tests.
  • After editing composer.json by hand: composer update for the packages whose constraints you changed; otherwise composer install warns that the lock file is not up to date.

Update options

OptionEffect
composer update vendor/pkgUpdate only that package; its dependencies stay locked when possible
-w, --with-dependenciesAlso allow its dependencies to update, except those that are root requirements
-W, --with-all-dependenciesAlso allow all its dependencies to update, including root requirements
--lockOnly refresh the lock file hash and metadata; no versions change
--dry-runPrint the operations without changing anything
--prefer-lowestInstall the lowest allowed versions; libraries use it in CI to test their minimum constraints

When an update cannot satisfy every constraint, Composer stops with Your requirements could not be resolved to an installable set of packages and lists the conflicting requirements; the lock file and vendor/ stay as they were.

FAQ

Why does composer install say the lock file is not up to date?

composer.json was edited after composer.lock was written, so the lock no longer matches it. Run composer update for the packages you changed (or composer update --lock if only metadata changed) and commit the new lock file.

Does composer require run update?

Yes, for the package you add: composer require vendor/pkg edits composer.json and updates that package and what it needs in composer.lock, leaving other locked versions alone.

Is it safe to delete composer.lock and run composer update?

Only if you are ready for every dependency to move to the newest allowed version at once. It is the largest possible upgrade; updating named packages is easier to review and test.

Sources