Search code examples
packagist

What's the difference between ~ and ^ in packagist


I'm a bit confused the difference between '~' and '^' in packagist ,

code example in composer.json file:

 "require": {
             "doctrine/dbal": "^2.6",      //this is using '^' symbol
             "garygreen/pretty-routes": "~0.0.6"    //this is using '~' symbol
            },

Can someone explain this for me ?


Solution

  • The ~ operator is best explained by example: ~1.2 is equivalent to >=1.2 <2.0.0, while ~1.2.3 is equivalent to >=1.2.3 <1.3.0. As you can see it is mostly useful for projects respecting semantic versioning. A common usage would be to mark the minimum minor version you depend on, like ~1.2 (which allows anything up to, but not including, 2.0).

    The ^ operator behaves very similarly but it sticks closer to semantic versioning, and will always allow non-breaking updates. For example ^1.2.3 is equivalent to >=1.2.3 <2.0.0 as none of the releases until 2.0 should break backwards compatibility. For pre-1.0 versions it also acts with safety in mind and treats ^0.3 as >=0.3.0 <0.4.0.

    From: https://getcomposer.org/doc/articles/versions.md#tilde-version-range-