Bundler could not find compatible versions for gem - ruby-on-rails-3

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

Related

An error occurred while installing pg (0.12.2), and Bundler cannot continue

I'm following the Michael Hartl Ruby on Rails Tutorial & there is a part where he is he he instructs you to update your Gemfile to include:
group :production do
gem 'pg', '0.12.2'
end
And then enter the below commands in your terminal:
bundle update
bundle install --without production
When you run the bundle update command it throws back the below errors.
sample_app:$ bundle update
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.0.3)
Using i18n (0.6.4)
etc
[omitted lines for brevity]
etc
Using railties (3.2.12)
Using coffee-rails (3.2.2)
Installing diff-lcs (1.1.3)
Using jquery-rails (2.0.2)
Installing pg (0.12.2)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/ross/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
etc
[omitted lines for brevity]
etc
Gem files will remain installed in /home/ross/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2 for inspection.
Results logged to /home/ross/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2/ext/gem_make.out
An error occurred while installing pg (0.12.2), and Bundler cannot
continue.
Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.
sample_app:$
I was able to overcome this error easily be removing the 'pg', '0.12.2' gem from the Gemfile & replacing it after running the bundle update command. This seems to work fine as the 'pg', '0.12.2' gem is aslo omitted in the without production flag in the latter bundle install --without production.
The 'pg', '0.12.2' gem is only needed for deploying to heroku with the correct database & everything works fine even when I deployed it to heroku but I'm just wondering if this is an error in the Tutorial or am I missing something bigger here?
It's also annoying to have to remove this Gem everytime I run bundle update, is bundle update really that necessary?
Thanks in Advance
I'm following the same tutorial and I think it's redundant to run update without modifying existing dependency, but in this case it's even causing problems because update command has not --without argument.
I stumbled upon Rails 3 cheatsheet which mentions bundler workflow this way:
After adding or removing dependencies from Gemfile
$ bundle
Commit Gemfile and Gemfile.lock
After modifying existing dependency versions
$ bundle update
Commit Gemfile and Gemfile.lock
I read man pages for bundle update and tried RECOMMENDED WORKFLOW which consists of running bundle update after bundle install.
In my case (some output omitted):
$ bundle install --without production
Resolving dependencies...
Using rake (10.0.3)
...
Installing rspec-core (2.11.1)
Your bundle is complete!
Gems in the group production were not installed. <-- check
$ bundle update
Resolving dependencies...
Using rake (10.0.3)
...
Using uglifier (1.2.3)
Your bundle is updated!
Gems in the group production were not installed. <-- check
I tried it with new RVM gem set and everything was installed correctly.
After that Gemfile.lock contains pg (0.12.2) and deploying to Heroku works.
RECOMMENDED WORKFLOW
In general, when working with an application managed with bundler, you
should use the following workflow:
After you create your Gemfile for the first time, run
$ bundle install
Check the resulting Gemfile.lock into version control
$ git add Gemfile.lock
When checking out this repository on another development machine, run
$ bundle install
When checking out this repository on a deployment machine, run
$ bundle install --deployment
After changing the Gemfile to reflect a new or update dependency,
run
$ bundle install
Make sure to check the updated Gemfile.lock into version control
$ git add Gemfile.lock
If bundle install reports a conflict, manually update the specific
gems that you changed in the Gemfile
$ bundle update rails thin
If you want to update all the gems to the latest possible versions
that still match the gems listed in the Gemfile, run
$ bundle update
Installation of postgres fails with this error : "Can't find the 'libpq-fe.h header"
Looks like a lot of people faced this problem, good news is : stackoverflow has the answer ;)
Can't find the 'libpq-fe.h header when trying to install pg gem
(or at least it should help you to look in the right direction)

Can't remove gem

Have a very strange problem. I have RVM and rails project. I used 'breadcrumbs_on_rails' gem and I had it in my Gemfile. After one update I got some errors in this gem, so I tried to roll back to previous version. I wrote version in Gemfile, ran bundle update - but nothing changed, there were still errors. I tried totally remove this gem from Gemfile, but... it's helpers were still working! I uninstalled gem completely, all versions, by running gem uninstall, cleared tmp folder of project, rebooted, but it is still working. What can be the reason?
Have you tried using
bundle exec gem uninstall GEM_NAME
For RVM users:
you have to use this method if you've set up a gemset for your particular project.
Running gem uninstall GEM_NAME from the project folder will uninstall GEM_NAME from your global/system level gemset instead of bundler's.
Problem was in conflict of two gems
gem twitter-bootstrap-rails have exactly same methods - add_breadcrumb and render_breadcrumbs. And breadcrumbs were rendered by this gem, not by breadcrumbs_on_rails.
So, it turns out, that gem was removed successfully

Omniauth + Devise Error: Could not find hashie-1.2.0

I add this to Gemfile:
gem 'omniauth-facebook'
Then I run bundle update. No problem so far. But when I run rails server I get this error:
Could not find hashie-1.2.0 in any of the sources
Run `bundle install` to install missing gems.
I thought that bundler was supposed to resolve and satisfy all dependencies, but I tried this anyway:
gem install hashie-1.2.0
Which gave this:
ERROR: Could not find a valid gem 'hashie-1.2.0' (>= 0) in any repository
ERROR: Possible alternatives: hashie-model
I'm new to Rails and I feel I'm at a dead end. Suggestions?
UPDATE: I also have run bundle install (to be exact bundle install --without production) several times. I get the same error when running rails server after that.
UPDATE: I aslo tried adding gem 'hashee' in the Gemfile before omniauth-facebook. No luck.
So I think you are just using bunder incorrectly.
bundle update doesn't resolve new dependencies, it simply looks at the gem manifest, which is stored in Gemfile.lock and updates those gems to the most recent gem allow by the constraints placed on them in the Gemfile.
Since you are trying to install a new gem, what you what to run is bundle install which will make a comparison between your Gemfile and your Gemfile.lock and install any gems that are not listed in your Gemfile.lock.
I think bundle install should do the trick for you.
As a side note, bundler tries to make this as easy as possible for you by aliasing bundle to bundle install. So, unless you are explicitly looking to update your gems, you can just type bundle and get the behavior that you are expecting.
I got it working. I think it was some problem with bundler. I did some different things, and I have to admit that I'm not 100% sure what fixed it. I think what did it was this:
gem uninstall bundler
gem install bundler
bundle install mail
However, it did not work until my second reinstall I think. Upon the install command, it installed everything, not just mail and its dependencies. The only other thing I did was to delete /usr/bin/bundler after the first reinstall. It did not reappear.

jruby, glassfish gem and bundler

I wonder if anybody has the following issue:
in a jruby environment, I can do:
gem install glassfish
no problem
But if I add
gem 'glassfish'
to my Gemfile and do
bundle install
it always complain glass fish gem cannot be found.
Any solution to this? Thanks
Do you have source "http://rubygems.org" in your Gemfile? I just tested
source "http://rubygems.org"
gem 'glassfish'
and it was fine:
$ cat > Gemfile
source 'http://rubygems.org'
gem "glassfish"
$ jruby -S bundle install
Fetching source index for http://rubygems.org/
Using rack (1.3.5)
Installing glassfish (1.0.3)
Using bundler (1.0.21)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Having said that, please keep in mind that glassfish gem is not maintained at this time. For the alternatives, please check this blog post: http://www.engineyard.com/blog/2011/taking-stock-jruby-web-servers/
It turned out to be something wrong with the Gemfile.lock. deleted the file and reinstall fixed the issue.

Can't force gems to a specific version in Rails 3 application

After a bundle update, I want to rollback some gem versions to a specific one. I've tried several options, but I can't do it.
Say I want to use arel in its 2.0.9 version. I did the following:
sudo gem uninstall arel -v 2.0.10
Then in the Gemfile:
gem 'arel', '~> 2.0.9'
And then:
bundle update
Then I get:
Installing arel (2.0.10)
I also tried with gem cleanup and deleting Gemfile.lock, but no.. I allways get the same arel 2.0.10 installed. Am I missing something? Thank you very much!
You're telling it to install any patch version greater than or equal to 2.0.9. If you want to specifically install that version just do this:
gem 'arel', '2.0.9'