質問

I've added a gem 'koala' to my Gemfile and seems to have thrown gem versions out of whack when I run the 'bundle install' command:

Bundler could not find compatible versions for gem "faraday":
In snapshot (Gemfile.lock):
faraday (0.6.1)

In Gemfile:
koala (~> 1.2.0beta1) depends on
  faraday (~> 0.7.4)

Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.

How can I resolve this conflict?

役に立ちましたか?

解決

Delete the contents of Gemfile.lock, and run bundle install again. That's been working for me.

他のヒント

Did you run bundle update as the error message points out? bundle install handles changes to the Gemfile and bundle update upgrades gems that are already managed by Bundler. The Gemfile.lock file locks in version numbers, bundle update will update any of those that aren't directly specified in your Gemfile (like gem 'rails', '3.0.9').

Deleting the Gemfile.lock will work, but running bundle update is better.

You can't simply delete you Gemfile.lock if that is a solution then why Gemfile.lock is exist in the first place, you code depend on the versions locked in this file, try to only update the Gem which cause the conflict by using bundle update gem_name and you have to check the ReadMe if any changes needed to work with the new version otherwise you are breaking your code or others code.

I found that by removing the specified version of rails solved the problem for me .... instead of:

gem rails, '4.0.4'

I did

gem rails

followed by deleting the Gemfile.lock and re-running bundle install

If deleting Gemfile.lock doesn't work there is another possibility:

It may be possible a gem you are depending on has inadvertently included its own Gemfile.lock in its .gem file. The solution is to update the offending gems to not include a Gemfile.lock, rebuild and reinstall.

An alternative is to go to your Gemfile.lock and delete all references to the offending gem (in this case the faraday gem). Then run bundle install and it'll update the Gemfile.lock to have compatible versions of the gem where it needs. If you want to be extra safe you can go to the Gemfile and specify the versions of the gems you want before doing this.

This was the only way I was able to get bundle install running for one of the systems that I'm maintaining. This system has a lot of old gems in its dependencies (58 gems at the time of writing) and so bundler has a hard time coping with it. If I delete the Gemfile.lock and run bundle install it'll blow up with multiple Bundler could not find compatible versions for gem xxxxxx errors. If I run bundle update it would also blow up with multiple Bundler could not find compatible versions for gem xxxxxx errors.

Note: Removing Gemfile.lock will have new entried to different gems. This might not be acceptable in your project. Your team or lead will not allow this.

If you are working on legacy codebase, for example Rails 3.2 or similar In case you hit this kind of errors,

see the last line of Gemfile.lock which seems like

  whenever (~> 0.9.4)
  wicked_pdf (= 1.1.0)
  will_paginate (= 3.1.8)
  wkhtmltopdf-binary-edge (~> 0.12.4.0)

BUNDLED WITH
   1.16.6

now install the version of bundler mentioned in the file. In my case its1.16.6.

gem install bundler -v 1.16.6 

now remove the older version. How?

$ gem uninstall bundler

Select gem to uninstall:
 1. bundler-1.16.6
 2. bundler-2.1.4
 3. All versions
> 2
Successfully uninstalled bundler-2.1.4

$ bundle -v     
Bundler version 1.16.6

Now it will install successfully

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top