简体   繁体   中英

How to install a specific version of package using Composer?

I am trying to install a specific version of a package using Composer. I tried composer install and composer require but they are installing the latest version of the package. What if I want an older version?

composer require vendor\/package:version<\/code>

例如:

composer require refinery29\/test-util:0.10.2<\/code>

"

添加双引号以在版本号中使用插入符运算符。

composer require middlewares/whoops "^0.4"

As @alucic mentioned, use:

composer require vendor/package:version

or you can use:

composer update vendor/package:version

You should probably review this StackOverflow post about differences between composer install and composer update .

Related to question about version numbers, you can review Composer documentation on versions , but here in short:

  • Tilde Version Range ( ~ ) - ~1.2.3 is equivalent to >=1.2.3 < 1.3.0
  • Caret Version Range ( ^ ) - ^1.2.3 is equivalent to >=1.2.3 < 2.0.0

So, with Tilde you will get automatic updates of patches but minor and major versions will not be updated. However, if you use Caret you will get patches and minor versions, but you will not get major (breaking changes) versions.

Tilde Version is considered a "safer" approach, but if you are using reliable dependencies (well-maintained libraries) you should not have any problems with Caret Version (because minor changes should not be breaking changes.

just use php composer.phar require

php composer.phar require doctrine/mongodb-odm-bundle 3.0

Suppose you want to install Laravel Collective. It's currently at version 6.x but you want version 5.8. You can run the following command:

composer require "laravelcollective/html":"^5.8.0"

A good example is shown here in the documentation: https://laravelcollective.com/docs/5.5/html

In your composer.json , you can put:

{
    "require": {
        "vendor/package": "version"
    }
}

then run composer install or composer update from the directory containing composer.json . Sometimes, for me, composer is hinky, so I'll start with composer clear-cache; rm -rf vendor; rm composer.lock composer clear-cache; rm -rf vendor; rm composer.lock composer clear-cache; rm -rf vendor; rm composer.lock before composer install to make sure it's getting fresh stuff.


Of course, as the other answers point out you can run the following from the terminal:

composer require vendor/package:version

And on versioning:
- Composer's official versions article
- Ecosia Search

I tried to require a development branch from a different repository and not the latest version and I had the same issue and non of the above worked for me :(

composer require [vendorName]/[packageName]:dev-[gitBranchName]

Curl can be used to download a specific version:

curl -O "https://getcomposer.org/download/1.10.17/composer.phar"
chmod a+x composer.phar
sudo mv composer.phar /usr/local/bin/composer

composer require package-name version-number

Example: composer require "laravel/tinker": "^2.5"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM