سؤال

In my Gemfile

source 'https://rubygems.org'
ruby '2.1.0'
gem 'rails', '4.0.1'
gem "faraday"
gem "faraday_middleware"
gem "twitter", github: 'sferik/twitter'

if I run

$ bundle install

I get

Bundler could not find compatible versions for gem "faraday": In Gemfile:

twitter (>= 0) ruby depends on
  faraday (~> 0.9.0) ruby

  faraday (0.8.9)
هل كانت مفيدة؟

المحلول

TL;DR: Try running bundle update.

Bundler tries to find gems that match in such a way that all their dependencies also match. So consider this:

  • gem A v1 depends on B v1
  • gem A v2 depends on B v2
  • gem C v1 depends on B v1
  • there is no version of C that knows how to handle B v2.

In this case, Bundler will choose (or even downgrade) A to v1, so that you can A and C running next to each other.

However there are a couple of things that might prevent this from happening, and that will cause the error you are seeing:

  1. There is no A v1, so no match can be made at all. You're stuck in this case, those gems will not work together at all.
  2. You've already installed A v2 and you are adding C later. This means Bundler needs to downgrade A, but it doesn't do downgrades/upgrades when only running bundle install. You'd have to specifically say that it needs to recalculate the dependencies by running bundle update A or for all the gems in your gemfile: bundle update.
  3. One of the gems is from a git repository. Git repositories don't really have versions like gems hosted on rubygems.org do. This means that Bundler will only fetch the latest version and cannot downgrade that gem. You need to specify a branch or revision manually in this case.

My guess is that you are looking at scenario 2. You've already installed (and locked down on) version 0.8.9 of faraday. By adding twitter, your previous lock needs to be updated.

Be careful of running bundle update without arguments however. It will try to get the latest versions of every gem in your gemfile, which might not be what you want.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top