How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: Install a Specific Version of a Package Using Composer (Exact Version + Examples)
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > Install a Specific Version of a Package Using Composer (Exact Version + Examples)
Web Development

Install a Specific Version of a Package Using Composer (Exact Version + Examples)

how7o
By how7o
Last updated: January 14, 2026
5 Min Read
Install a specific version of a package using Composer (composer require vendor/package:2.1.0)
SHARE

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.

Contents
  • The quick answer (exact command)
  • What actually happens when you run composer require
  • How to find available package versions
    • Option 1: Check Packagist
    • Option 2: Use Composer itself
  • Exact version vs version constraints (what I recommend)
    • Common constraint examples
  • How to downgrade to a specific version (real-world fix)
  • Troubleshooting (common Composer errors)
    • 1) “Could not find a matching version”
    • 2) Dependency conflicts
  • 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).

Install a specific version of a package using Composer (composer require vendor/package:2.1.0)

The quick answer (exact command)

To install an exact package version with Composer, use:

composer require vendor/package:version

Example: if you want to install version 2.1.0 of example/package, run:

composer require example/package:2.1.0

Windows 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.lock so 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 --all

This 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.1 or ~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.1

How 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.1 when the package only has 2.1.0 releases.
  • 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-dependencies

If 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)
Composer version install steps: find version → composer require package:version → verify → commit composer.lock

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.

TAGGED:composercomposer.jsonDependency ManagementLaravelPackagistphpSymfonyVersioning

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Include Composer packages in plain PHP projects How to Include Composer Packages in Plain PHP Projects (Autoload + Example)
Next Article Return or throw an error in Laravel (JSON response vs exception) How to Manually Return or Throw an Error Exception in Laravel
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026
Caddy server — automatic HTTPS, 3-line Caddyfile vs 25-line nginx config
How to Install Caddy Server on Ubuntu (Automatic HTTPS, Drop-in nginx Alternative)
May 24, 2026
Cloudflare Tunnel — outbound-only connection from server, no inbound port forward
How to Install Cloudflare Tunnel on Ubuntu (Expose Local Services, No Port Forwarding)
May 24, 2026
WireGuard encrypted tunnel between server and clients with lock icons
How to Set Up WireGuard VPN on Ubuntu (Server, Linux Client, and iOS)
May 24, 2026

You Might Also Like

Laravel old() helper for repopulating form inputs
Web Development

How Laravel’s old() Helper Works (and Why It Sometimes Doesn’t)

6 Min Read
WooCommerce auto add to cart on visit — template_redirect hook and cart dedup
Web Development

How to Automatically Add a Product to Cart on Visit in WooCommerce

8 Min Read
Laravel migration column types cheat sheet
Web Development

Laravel Migration Column Types — Cheat Sheet

5 Min Read
How to use localStorage in JavaScript shown in a browser storage panel
Web Development

How to Use localStorage in JavaScript (With Real Examples + Troubleshooting)

8 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?