Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between >= and ~ in package.json dependencies?

Tags:

npm

"foo": "~0.2.1"
"foo": ">= 0.2.1"

What's the difference?

like image 770
callum Avatar asked Oct 30 '25 18:10

callum


2 Answers

>= means any version equal or bigger to the mentioned release. For example 42.42.42 would be fine with >= 0.2.1 requirement (no matter how incompatible it would be in practice). Also, it means that 0.2.1-beta is not fine, as beta was before final release.

~ means reasonably close to the specified version (as in, compatible). It takes the semantic versioning definition, so any major version jumps aren't considered to be compatible (higher than the last number in specified version). For example, 42.42.42 or 0.3.0 is not fine with ~0.2.1 requirement. However, 0.2.1-beta or 0.2.42 is allowed, as it's reasonably close to the final version.

like image 76
Konrad Borowski Avatar answered Nov 01 '25 13:11

Konrad Borowski


Tilde means next significant release. In your case, it is equivalent to >= 2.0, < 3.0.

A simple rule-of-thumb way is that the ~ allows the last digit to go up. e.g. ~2.2 means 2.2 and any 2.x where x is 2 or above. ~2.1.3 on the is also any 2.1.x where x is 3 or above.

http://getcomposer.org/doc/01-basic-usage.md#package-versions

like image 37
Pakspul Avatar answered Nov 01 '25 14:11

Pakspul