I thought I understood how Bundler works with gems, but after something that recently happened, I am not sure I have it right.
I am developing an Rails application. To start off (and just so I would get familiar with the Rails environment which I haven’t worked in before), I did not use an IDE. But, because I’m missing out on some of the advantages of an IDE, I just started using RubyMine. As part of the RubyMine setup, it asked to update all my gems for my existing project.
After that, I could not run “rake [anything]”. Every time I did, I received an error of:
You have already activated rake 0.9.3.beta.1, but your Gemfile
requires rake 0.9.2.2. Using bundle exec may solve this.
I was okay updating to the next version of rake – that wasn’t a problem – but I don’t understand what happened in the first place. What happened that I “activated” a newer version of rake. Ultimately, I ended up solving the problem by putting
gem 'rake', '0.9.3.beta.1'
in my Gemfile and running
bundle update rake
But, I’m still not sure what happened here. If I was using 9.2.2 before, why did it all of a sudden blow up like that and how can I prevent that in the future?
You should really consider installing and using RVM or Rbenv to manage your ruby versions and gemsets. If you go the Rbenv way, the rbenv-gemset plugin can be used to manage gemsets similar to how RVM natively does.
At some point between your last
bundleexecution and installing/configuring/running RubyMine you must have installedrake 0.9.3.beta.1. Because you’re not managing your gems through gemsets like RVM or Rbenv will do for you, the default version of Rake became0.9.3.beta.1instead of the version installed by bundler,0.9.2.2.The above error suggests your
Gemfilehad something likewhich does not allow the version of rake being used to be anything but
0.9.2.2.If you do in fact have
0.9.2.2on your system in addition to the0.9.3.beta.1and yourGemfileis configured for0.9.2.2, instead of runningyou can run
and bundler will run
some:taskthrough the0.9.2.2version of rake. Running tasks related to gems found in aGemfilethrough bundleer withbundle exec ...is considered good practice regardless of using RVM or Rbenv.You can read about
bundle exechere.