What does the ~> symbol mean in a bundler Gemfile?

Ruby on-RailsBundlerGemfile

Ruby on-Rails Problem Overview


What does the -> mean next to a version number in a Gemfile?

For example:

gem 'sass-rails',   '~> 3.1.5'

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

From the bundler website:

> The specifier ~> has a special meaning, best shown by example:
>'~> 2.0.3' is identical to '>= 2.0.3' and '< 2.1.'
>'~> 2.1'     is identical to '>= 2.1'    and '< 3.0'.
>'~> 2.2.beta' will match prerelease versions like '2.2.beta.12'.

See https://bundler.io/gemfile.html and http://guides.rubygems.org/patterns/#pessimistic-version-constraint

Solution 2 - Ruby on-Rails

You usually use this to tell bundler that it's ok to install some minor updates (last digit specified can vary) but not to install some major update.

SO

~> 2.0.3 means >= 2.0.3< 2.1

and

~> 2.1 means >= 2.1< 3.0

Read more at https://bundler.io/gemfile.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbradView Question on Stackoverflow
Solution 1 - Ruby on-RailsTim BrandesView Answer on Stackoverflow
Solution 2 - Ruby on-RailsUkoView Answer on Stackoverflow