I ran into this while working on a PHP project where everything was “fine”… until a teammate updated dependencies and my build started failing. The package itself wasn’t broken — it was the newer version that introduced a change our codebase wasn’t ready for. That’s when I needed to install a specific version of a package using Composer instead of just pulling the latest release.
- The quick answer (exact command)
- What actually happens when you run composer require
- How to find available package versions
- Exact version vs version constraints (what I recommend)
- How to downgrade to a specific version (real-world fix)
- Troubleshooting (common Composer errors)
- Helpful links (add these for Yoast)
- Final thoughts
The fix was simple once I knew the syntax: you can tell Composer the exact version right in the composer require command. In this post, I’ll show the exact command, how to find available versions, and a few real-world tips (downgrades, conflicts, and version constraints).
The quick answer (exact command)
To install an exact package version with Composer, use:
composer require vendor/package:versionExample: if you want to install version 2.1.0 of example/package, run:
composer require example/package:2.1.0Windows tip: if your terminal is picky, wrap it in quotes:
composer require "example/package:2.1.0"What actually happens when you run composer require
Composer will do three important things:
- Add the package + version constraint to your
composer.json - Download the package and its dependencies
- Update
composer.lockso the installed versions stay consistent across servers and teammates
That last part (composer.lock) is the reason your production server matches your local machine. If you’re using Git, commit composer.lock too.
How to find available package versions
Before pinning a version, you need to know what versions exist. Here are the two easiest ways I use:
Option 1: Check Packagist
Go to Packagist and search the package name. You’ll see a version list (tags/releases). This is the fastest method.
Option 2: Use Composer itself
If the package is already installed (or you want more details), run:
composer show vendor/package --allThis prints available versions plus extra info. Super useful when you’re not sure what release you should pin.
Exact version vs version constraints (what I recommend)
You can install a specific version of a package using Composer in two common ways:
- Exact version (hard pin):
2.1.0 - Constraint (allow safe updates):
^2.1or~2.1
If you’re fixing a break right now, an exact version is fine. But long-term, I usually prefer a constraint so I still get bug fixes without jumping to a breaking major version.
Common constraint examples
# exact version (pin)
composer require example/package:2.1.0
# allow updates within major version (recommended in many cases)
composer require example/package:^2.1
# allow updates within minor version (more strict)
composer require example/package:~2.1How to downgrade to a specific version (real-world fix)
This was my original problem: a newer version got installed and things broke. Downgrading is basically the same command — you just require the older version.
composer require example/package:2.1.0 --with-all-dependencies--with-all-dependencies helps when the package needs compatible dependency versions too (this avoids a lot of “conflict” errors).
Troubleshooting (common Composer errors)
1) “Could not find a matching version”
- Double-check the version exists (Packagist list).
- Make sure you didn’t type
2.1when the package only has2.1.0releases. - If it’s a dev branch, you may need something like
dev-main(not recommended for production).
2) Dependency conflicts
If Composer complains about conflicts, try the require command with:
composer require example/package:2.1.0 --with-all-dependenciesIf you’re working on a big framework project (Laravel/Symfony), conflicts often happen because other packages also restrict versions. In that case, you may need to update a small group of packages together.
Helpful links (add these for Yoast)
- Composer docs: require command
- Composer docs: version constraints
- Packagist (PHP package repository)
- Related: How to install Composer on Ubuntu (internal link)
Final thoughts
Once you know the syntax, it’s straightforward to install a specific version of a package using Composer. The main rule I follow is: pin exact versions when you’re fixing a breaking change quickly, then switch to a sensible constraint so you still receive bugfix updates without surprises. And always commit composer.lock so your production server stays identical to your local setup.

