Streamline Streamline - 11 months ago 108
Ruby Question

How to resolve bundler gem version conflict with json gem

I want to update the json gem to version 2.0.2 in my app. It is currently loaded as a dependency at version 1.8.3.

So, I added

gem 'json', '>= 2.0.2'

to my Gemfile and I type

bundle update json

and I get

Fetching gem metadata from
Fetching version metadata from
Fetching dependency metadata from
Resolving dependencies...
Bundler could not find compatible versions for gem "json":
In Gemfile:
json (>= 2.0.2)

paperclip (~> 4.2.0) was resolved to 4.2.4, which depends on
activesupport (>= 3.2.0) was resolved to 4.2.7, which depends on
json (>= 1.7.7, ~> 1.7)

Which doesn't make sense to me because I thought the
json (>= 1.7.7, ~> 1.7)
is saying that activesupport 4.2.7 is dependent on at least version 1.7.7 of the json gem, so 2.0.2 should not be a conflict, no?

What is the correct interpretation here?

What steps can I take so that I can add json v2.0.2 gem to my rails v4.2.7 app successfully?

Answer Source

The json requirement has two parts. The first is >= 1.7.7 meaning the Gem must be greater than or equal to 1.7.7. 2.0.2 is, in fact, greater than 1.7.7, so you satisfy that requirement. However, the second part of that is that it must also be ~> 1.7 (pronounced "tiddle-wakka") is what's called a Pessimistic Constraint. It required that the first elements of the version number match but the last can be greater than or equal to the number given. So, for example, 1.7.0 would satisfy the constraint. As would 1.7.9 or 1.9.9, or even 1.423.8. However, 2.0.0 would fail that constraint because the major version number doesn't match the given value of "1".