Posts Learn Components Snippets Categories Tags Tools About

How to Install a Specific Version of Package Using Composer?

Learn how to specify package version when installing Composer dependency for PHP projects.

Created on Sep 27, 2021


Sometimes you might need to specify different package versions when installing a Composer dependency and to do that you can pass in the version after the package name.

Default Composer Require Command

The default way of installing/requiring a package is as follows. By default, this will install the latest available package for the project.
composer require vendor/package

Composer Require Command With Package Version

To specify the version number you can pass in after the package name like below. Do note that the version must be the version of how the package vendor specifies it. 
composer require vendor/package:version
So let's say you are installing the Intervention Image package which is to manipulate Image, you can write your command like below.
comopser require intervention/image:2.6.0
The benefit of specifying the package version is that sometimes the latest version of the package has a higher dependency requirement than your current project, so the only way to have the package is to install the older version.

Other Reads

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️