How do I keep all gems in Gemfile compatible after an update

Theo Scholiadis picture Theo Scholiadis · Oct 27, 2011 · Viewed 12.3k times · Source

My question has already been asked here, but I am trying to understand the reasons behind it as opposed to how to work around it.

The error I got was;

You have already activated rspec-core 2.7.1, but your Gemfile requires rspec-core 2.6.4. Using bundle exec may solve this. (Gem::LoadError)

Now I have been given various solutions like using "mpapis-bundler", or to create a shorthand for "bundle exec", but I was under the impression that that was what

$bundle install --binstubs

was for.

More specifically, since I have no version numbers stated in my gemfile for rspec-rails, why do I have this incompatibility? My error also occurred when I tried

$rake db:migrate

telling me that

You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Consider using bundle exec.

Any explanations would be appreciated.

EDIT:
All my gems for my app are in a gemset, and I have updated my gems again. Should an update not make sure that related gems are compatible?

Answer

apneadiving picture apneadiving · Oct 27, 2011

This happens when you install more recent gems in your system than the one in your Rails app.

Bundler simply tells ou that you must stick with those your Gemfile states.

This is the purpose of running:

bundle exec rake db:migrate

-> running the very same rake version your Gemfile provides.

Concerning updating gems from gemfile, simply do:

bundle update

The easiest way to avoid this kind of boring stuff is to isolate your gems by creating gemsets. I use RVM for this purpose.