Skip to content

Instantly share code, notes, and snippets.

@3v0k4
Last active February 17, 2022 08:28
Show Gist options
  • Save 3v0k4/3625f3922e3035811e937155fd635e55 to your computer and use it in GitHub Desktop.
Save 3v0k4/3625f3922e3035811e937155fd635e55 to your computer and use it in GitHub Desktop.
Version ranges in different languages (Ruby, JavaScript, Rust)

What The Version aka WTV?

Version ranges in different languages: Ruby, JavaScript, Rust.

It's clear what >, >=, <, or <= mean. But what about those other cryptic symbols?

Npm (package.json)

Version Equal To Only Highlighted Result
~1.10.100 >=1.10.100 && <1.11.0 1.10.100 Latest patch
~1.10 >=1.10.0 && <2.0.0 1.10.0
~1 >=1.0.0 && <2.0.0 1.0.0
^1.10.100 >=1.10.100 && <2.0.0 1.10.100 Latest minor
^0.10.100 ~0.10.100 0.10.100
^0.0.100 >=0.0.100 && <0.0.101 0.10.100

Tilde ~ Allows patch-level changes if a minor version is specified. Otherwise, allows minor-level changes.

Caret ^ Allows changes that do not modify the left-most non-zero digit. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X, and no updates for versions 0.0.X.

Ruby (Gemfile)

Version Equal To Only Highlighted Result
~>1.10.100 >=1.10.100 && <1.11.0 1.10.100 Latest patch
~>1.10 >=1.10.0 && <2.0.0 1.10.0
~>1 >=1.0.0 && <2.0.0 1.0.0

Twiddle-wakka or pessimistic version constraint ~> Allows patch-level changes if a minor version is specified. Otherwise, allows minor-level changes (same as ~ in Npm).

Rust (Cargo.toml)

Version Equal To Only Highlighted Result
~1.10.100 >=1.10.100 && <1.11.0 1.10.100 Latest patch
~1.10 >=1.10.0 && <1.11.0 1.10.0
~1 >=1.0.0 && <2.0.0 1.0.0
^1.10.100 >=1.10.100 && <2.0.0 1.10.100 Latest minor
^0.10.100 ~0.10.100 0.10.100
^0.0.100 >=0.0.100 && <0.0.101 0.0.100

Tilde ~ If you specify a major, minor, and patch version or only a major and minor version, only patch-level changes are allowed. If you only specify a major version, then minor- and patch-level changes are allowed.

Caret ^ Allows changes that do not modify the left-most non-zero digit. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X, and no updates for versions 0.0.X.

@ravicious
Copy link

It’s worth noting that in Cargo.toml an implicit caret will be used if you don’t specify any operator.

https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-cratesio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment