Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 842
Theo Scholiadis Avatar asked Oct 27 '11 16:10

Theo Scholiadis


2 Answers

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.

like image 113
apneadiving Avatar answered Sep 22 '22 07:09

apneadiving


Regarding the rake version 0.9.2.2, either ways to do is create a new gemset for the project and maintain the gem version matching your Gemfile.

For instance if there are two rake gem containing versions 0.9.2 and 0.9.2.2, specifying rake version '0.9.2' though installs, but does not run any tasks apart from blowing error saying

'You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this.'

I expect bundle install to lock the gem version in Gemfile.lock and pick the rake 0.9.2, but it looks in the gemset, where by default rake 0.9.2.2 is enabled.

Just reminding the purpose of bundle install from agile web development with rails book,

'bundle install will use the Gemfile.lock as a starting point, and install only the versions of the various gems as specified in this file. For this reason, it is important that this file gets checked into your version control system, as this will ensure that your colleagues and deployment targets will all be using the exact same configuration.'

but it doesn't work that way,

The better is to uninstall rake 0.9.2.2 and use rake 0.9.2 or, use bundle update rake, that updates the rake version in Gemfile.lock to 0.9.2.2

like image 27
hariharan kumar Avatar answered Sep 21 '22 07:09

hariharan kumar