Summary of version constraint operators used in major package managers and configuration tools across languages. It includes their syntax, common meaning, and examples.
Operator | Meaning | Used In | Example | Resolves To |
---|---|---|---|---|
= |
Exact version | RubyGems, npm, Cargo, Composer | = 1.2.3 |
Only 1.2.3 |
== |
Exact version (Python-style) | pip/requirements.txt | ==1.2.3 |
Only 1.2.3 |
!= |
Not equal to version | pip, Composer | !=1.2.3 |
Any version except 1.2.3 |
> |
Greater than | All | >1.2.3 |
1.2.4 , 2.0.0 , etc. |
< |
Less than | All | <1.2.3 |
Anything before 1.2.3 |
>= |
Greater than or equal to | All | >=1.2.3 |
1.2.3 , 2.0.0 , etc. |
<= |
Less than or equal to | All | <=1.2.3 |
1.2.3 , 1.2.2 , etc. |
~> |
Pessimistic constraint (“twiddle-waka”) | RubyGems, Terraform | ~> 1.2.3 |
>= 1.2.3 , < 1.3.0 |
^ |
Compatible with (SemVer safe) | npm, Cargo | ^1.2.3 |
>= 1.2.3 , < 2.0.0 |
* |
Wildcard | npm, Composer | 1.2.* |
>= 1.2.0 , < 1.3.0 |
- |
Range | npm, pip | 1.2.3 - 2.0.0 |
>= 1.2.3 , <= 2.0.0 |
~ |
Approximate match (deprecated in npm) | Old npm | ~1.2.3 |
>= 1.2.3 , < 1.3.0 |
!= |
Not equal to | pip, Composer | != 1.2.3 |
All except 1.2.3 |
` | ` | Logical OR | npm, Composer | |
>= < |
Inclusive lower and exclusive upper bound | pip | >=1.2.0, <2.0.0 |
Match versions in that range |
latest |
Always pull the most recent version | npm, Docker, etc. | latest |
Depends on registry |