How to install a specific version of package using Composer?

前端 未结 6 1120
野趣味
野趣味 2020-11-28 01:05

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 la

6条回答
  •  悲哀的现实
    2020-11-28 01:36

    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.

提交回复
热议问题