thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

Semantic versioning constraints

• 124 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

When working with semantic versioning a.k.a. semver, it’s often useful to use range constraints1 to express the versions you’re interested in.

The most useful ones are the tilde (~) and the circumflex / hat / caret (^)2:

  • ~4.2.1: picks up 4.2.x for x >= 1
  • ^5.0.2: picks up 5.x.y for x >= 0 and y >= 2

Popular software tooling that uses them include:

  • nodejs / npm packages
  • terraform
  • ruby gems (here ~> is used instead of simply ~)

Sometimes I use https://jubianchi.github.io/semver-check to double-check3, or to teach teammates how the range constraints work.


  1. Or constraint ranges? 🤔 ↩︎

  2. In Portuguese we say “acento circunflexo” (circumflex accent). In English, AFAIK, “caret” is the most precise term however people typically refer to it as “hat”. ↩︎

  3. Example↩︎