Composer: Check PHP package versions

php
tutorial
composer
Nabil Hassen
Nabil Hassen
Sep 12, 2025
Composer: Check PHP Package Versions in 4 Ways
Last updated on Sep 12, 2025
Table of contents:

TL;DR: You can check a Composer package version using:

composer show laravel/framework

How to Check Composer Package Version in PHP

When working with Composer in PHP, it’s often necessary to check which version of a package you’re using. This can be useful for debugging, upgrading, or ensuring compatibility with your codebase. In this guide, we’ll look at several ways to find the version of a Composer package.

1. Check with Composer CLI

The simplest way is to use Composer’s built-in command-line tools.

composer show vendor/package-name

Example:

composer show laravel/framework

This will output details such as version, description, and dependencies.

If you want a list of all installed packages with versions:

composer show --installed

2. Check composer.lock File

Another way is to open the composer.lock file in your project root. Search for the package name and you’ll find its exact version.

Example snippet from composer.lock:

{
"name": "laravel/framework",
"version": "v12.0.1"
}

This ensures you’re seeing the exact version installed.

3. Check vendor/composer/installed.json File

Composer also stores installed package details in the /vendor/composer/installed.json file. Here you can find the version of each installed package. This file is machine-readable and can be parsed programmatically.

4. Programmatically in PHP

If you need to check a package version directly inside your PHP application, you can use Composer\InstalledVersions class.

<?php
 
require __DIR__ . '/vendor/autoload.php';
 
use Composer\InstalledVersions;
 
$version = InstalledVersions::getVersion('laravel/framework');
echo "Laravel version: $version";

This method is available in Composer 2.0 and later.

Conclusion

You can check the version of a Composer package using:

  • Composer CLI commands (composer show)
  • composer.lock file
  • installed.json file
  • Programmatically via Composer\InstalledVersions

For quick checks, the CLI is easiest. For automated checks inside your PHP project, use the InstalledVersions class.

Nabil Hassen
Nabil Hassen
Full Stack Web Developer

Stay Updated.

I'll you email you as soon as new, fresh content is published.

Thanks for subscribing to my blog.

Latest Posts