composer: How to find the exact version of a package?

composer: How to find the exact version of a package?

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

Stefan Bogdanescu

Founder & Senior Architect

composer: How to find the exact version of a package?

When developing a library, pinning dependencies to specific semantic version ranges is crucial for maintaining stability across different consumer environments. However, the workflow often involves an intermediate step where you need to identify the latest available version before settling on a constraint like 1.3.*. A common point of confusion arises when inspecting the generated composer.lock file after running an install command with a wildcard specifier like "*.*.*".

In many cases, particularly within development environments or specific repository configurations, the composer.lock file might list the installed package under version: "dev-master" alongside a source-reference pointing to a specific Git commit hash. This happens because Composer treats the latest state of the repository as a valid version constraint when using wildcards that resolve to development branches. Seeing this entry can be misleading if you assume it represents a tagged release like 1.3.5. The file explicitly documents what was installed, but it doesn't always display the human-readable semantic version you are looking for in that specific field.

To extract the actual semantic version number from this state, you should look at the package metadata directly from the remote repository rather than inferring it solely from the lock file's dev-master entry. The most reliable method is to query Composer's API or inspect the package's source control history. You can retrieve the list of available versions by running a command that queries the version constraint directly:

composer show monolog/monolog --all

This command outputs every version currently maintained in the repository, sorted from oldest to newest. By examining this output, you can identify the latest stable release (e.g., 3.x, 2.x, or 1.x) and its corresponding version number. Once you have identified the highest patch version within your desired minor branch—say, 1.3.5 in the example provided—you can confidently update your composer.json requirement from "*.*.*" to a more restrictive pattern like "^1.3" or "1.3.*".

Using "*.*.*" is generally discouraged for production libraries because it implies no stability guarantees, potentially pulling in breaking changes if the upstream maintainers release a major version update immediately after your library goes live. By narrowing the requirement to a specific minor version range, you ensure that your library consumers get consistent behavior and that backward compatibility is preserved within that minor release cycle.

If you prefer not to use the CLI command, you can also inspect the composer.json of the package on Packagist or GitHub directly. Often, the latest tag on the repository corresponds to the latest stable version. However, relying on Git tags requires understanding the repository's release strategy, whereas Composer's API provides a programmatic way to verify the exact version string that matches your installation.

Ultimately, the composer.lock file serves as a snapshot of the dependency tree at the moment of installation. If it shows dev-master, it confirms that the installer resolved the wildcard to the default branch, not necessarily a tagged release. By cross-referencing this with the available versions list, you bridge the gap between the dynamic nature of version resolution and the static requirements needed in your library's definition file. This ensures that when you commit your composer.json, you are explicitly stating your dependency boundaries rather than leaving them open to the vagaries of the latest code on the default branch.

Our network