Reputation: 1069
I'm running Rails 3.2.1 & Ruby 1.9.2-p290 within an RVM environment
Within my dev folder, I have a number of different Rails apps, all running the above, but I haven't created separate gemsets
I created a new app with its own gemfile, ran bundle install etc and all was ok till I went back the the main app I was working on originally
When I now do a rake routes I get the error
rake aborted!
You have already activated rake 10.0.3, but your Gemfile requires rake 10.0.2. Using bundle exec may solve this.
I think I know how to get back on track, but here's what I don't understand:
When I look at the .rvm/gems/ruby-1.9.2-p290/gems folder, I can see a folder for each of the gems for rake-0.8.7, rake-0.9.2.2, rake-10.0.2, rake-10.0.3
So I have a version of rake 10.0.2 installed, my main app gemfile.lock calls for rake(10.0.2) and when I run bundle exec rake routes it does actually work (presumeably running 10.0.2?), but when I run a straight rake routes, Rails seems to want to run a different version of Rake that its not being asked to.
So my question is how do I know which version of an installed Gem is actually being run, given that calling for a particular version of an installed Gem seems not to do as you'd expect?
(separately, I guess that if I'm developing different apps within the same RVM space, I should probably be creating separate gemsets for each app?)
Upvotes: 2
Views: 4699
Reputation: 53158
this problem is fixed in rubygems 2.0 - Gemfile can be respected for loading any executable gem.
as for your problem RVM comes with my gem installed rubygems-bundler
and it should automatically resolve dependencies if possible - it would fallback to your problem if proper version is not installed, there is a ticket to change the situation to raise an exception in that case - https://github.com/mpapis/rubygems-bundler/issues/37
basically - make sure you run bundle install
before doing anything in the project, and rubygems-bundler
will ensure proper versions of gems are ran.
Upvotes: 6
Reputation: 1996
The problem is that when you have multiple versions of the same gem installed, the binary you will execute rake
is always the latest version. If your application then depends on an older version of that gem, it can't activate it, since the newer version is already loaded.
There are three solutions:
bundle exec rake
this will always use the version from your Gemfilebundle --binstubs
. This creates a ./bin
folder in your project. You can now access the binaries for the specified gem versions from your Gemfile. You can call rake with ./bin/rake
EDIT: As you mentioned you can also create separate gemsets to postpone the problem. There will be times though when you update a gem on a branch and then switch that you will get the error nonetheless.
Upvotes: 3