Can composer generate the `composer.lock` without actually download the packages?

Can composer generate the `composer.lock` without actually download the packages?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Can composer generate the composer.lock without actually download the packages?

There is a direct analogue to Ruby's bundle lock within the Composer ecosystem, but the answer requires distinguishing between metadata resolution and asset installation. While you cannot simply run a command that outputs the lock file contents without fetching any data from remote repositories, there are specific workflows where Composer resolves dependencies into a lock file while keeping the actual package archives off your machine.

The core mechanism relies on understanding what composer install actually does in two phases: it first resolves the dependency graph and writes composer.lock, then it downloads the .zip or .tar.gz archives to vendor/. If your goal is solely to generate a reproducible lock file—perhaps to commit it to version control without polluting your local disk with gigabytes of dependencies—you can utilize the --no-install flag.

composer update --no-install

Or, if you are starting fresh:

composer init
composer require vendor/package --no-interaction --no-install

When you invoke these commands, Composer connects to Packagist (or your configured repository), authenticates if necessary, and performs the full resolution algorithm. It checks for version constraints, handles platform requirements (like PHP versions or extensions), and calculates the exact set of packages needed to satisfy the composer.json requirements. The result is a fully populated composer.lock file that contains the precise hashes and versions required to ensure build reproducibility across environments.

The critical trade-off here is that Composer must download the metadata for every single package in the dependency tree, not just the top-level ones. This includes reading composer.json, composer.lock, and often composer/installed.json files from the remote repository to verify integrity and version compatibility. If a package has been removed from Packagist or if a critical dependency is missing, the command will fail before creating a valid lock file. You cannot skip the network request entirely; you are only skipping the step where those metadata archives are extracted into your vendor/ directory.

This approach is particularly useful in CI/CD pipelines or shared hosting environments where disk space is at a premium during the build phase but the lock file needs to exist for subsequent steps. However, be aware that the --no-install flag does not prevent Composer from downloading and installing dev dependencies if they are listed in your configuration. If you strictly need to avoid downloading anything other than the metadata required for resolution, you must also ensure your composer.json does not list dev packages, or you run the command with additional exclusions depending on your specific version of Composer.

Another relevant scenario involves using the --prefer-dist flag combined with --no-install. While this usually implies downloading the distribution archives rather than source code, it highlights that "not installing" primarily refers to not populating the vendor/ directory. If you are in an environment where you absolutely cannot fetch any remote data (e.g., strictly offline with no internet), generating a valid lock file from scratch is impossible without existing metadata caches or pre-downloaded archives.

For teams utilizing Laravel or similar frameworks, ensuring that the lock file is generated before committing code prevents "dependency hell" on staging servers. If you are looking for enterprise-grade deployment strategies or managed hosting solutions, resources like https://laravelcompany.com often provide insights into optimizing these workflows, though the fundamental Composer commands remain consistent across standard installations.

Ultimately, the --no-install flag provides a valid solution to your problem: you get the deterministic lock file without the bulk of the vendor directory bloating your working tree immediately after resolution.

Our network