Home » Tips » Meaning of tilde (~) caret (^) wildcard ( * ) in composer.json file


Summary: 
In this post, We are going to learn the meaning of tilde (~), caret (^),  wildcard ( * ) in composer.json file. When we install the composer you can see a file name composer.json is created. When we just open it we can see some sign near to version like tilde (~), caret (^) and wildcard ( *). For example, I show you
yii2 json file below:

Composer.json file different for different dependency.

Let’s start,
While we install any dependency through the composer we need to define which version of any dependency we are going to use that why we need the separate type symbol to define the versions. With the help of these symbols, you can define that which version of any dependency you want to use. You can also use logic operators (, often means AND and | means OR) to define the range of version. Even you can use some complex condition for the version by using comparators, for example, >=0.8.0,<0.10.0
Means of this is your version greater than 0.8.* and less than 0.9.*  (wildcard ( * )  means value lies between 0 to 9)

Let’s take a look of the tilde (~) and caret (^) symbol.

  • ~3.1.2 means >= 3.1.2,<3.2.0,
  • ~3.1    means >= 3.1.0,<4.0.0,
  • ~0.3   means >= 0.3.0,<1.0.0,
  • ~3       means >= 3.0.0,<4.0.0.

The caret symbol is a bit different:

  • ^3.1.2 means >= 3.1.2,<4.0.0,
  • ^3.1    means >= 3.1.0,<4.0.0 (just like ~3.1),
  • ^0.3   means >= 0.2.0,<0.4.0,
  • ^3       means >= 3.0.0,<4.0.0 (As it is like ~3).

That’s all 😃👍
Hope you understand still have any question you can comment below.

How to create dropdown in yii2 gridview
Top 7 commands of git you must learn

Back to top