views:

610

answers:

2

I am using rvm, doing the following:

rvm install ree    <--- (Ruby Enterprise Edition), or this can be 1.8.7 or 1.9.2
rvm ree
rvm gemset create 'proj'
cd path/to/proj
bundle install

so Gemfile in that project says:

gem 'rails', '3.0.0'

and bundle install is super fast, reporting

Using rails (3.0.0) 

but after that when I type

$ rails -v
/Library/Ruby/Site/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
    from /Library/Ruby/Site/1.8/rubygems.rb:214:in `activate'
    from /Library/Ruby/Site/1.8/rubygems.rb:1082:in `gem'
    from /usr/bin/rails:18

$ which rails
/usr/bin/rails

so bundle install doesn't install the rails as a gem? but if I type script/rails -v it shows it is 3.0.0

+4  A: 

This is correct. bundle install won't install Rails as a gem in the conventional sense. Now to explain why.

When Bundler runs an install, it will install the gems a directory: ~/.bundle/<type-of-ruby>/<version>/gems. This is different to the normal way of installing them to a system path. When a gem is installed at a system path, the executable is made available because that directory is within the load path. Now this is a bad thing, because you can only have one executable per gem. Have you got SomeGem v2 installed but want to use the generator from SomeGem v1? Too bad.

Bundler solves this problem by installing them into the afore-mentioned location and only requiring specific versions of the gems it needs (specified inside of Gemfile. By running simply rails, you're trying to run the system executable (as in one provided by doing gem install rails) rather than the Bundler one (provided by doing bundle install for a Rails project).

To run the one that Bundler installs you must run it like this bundle exec rails within a directory that contains a Gemfile that specifies any version of Rails. Bundler will load a specific version of Rails and you should now be able to run them side-by-side with the only tradeoff being the bundle exec prefix to commands.

Personally I've aliased this to be and two characters before some commands is a worthwhile tradeoff to avoiding The Seventh Circle of Gem Conflict Hell in my opinion.

Ryan Bigg
now, but every guide I saw (Official Rails guide, Rails Tutorial by Michael Hartl) says the way to use Rails is just "rails generate", and presumably, people need to `gem install rails` before they can have a project (or at least 1 person in the team), so that he can have `script/rails` and `bundle exec rails`. So this 1 person may be using SomeGem v1 and SomeGem v2 at the same time any way (Gem being Rails in this case). I think maybe a documentation can explain the 3 ways of invoking Rails...
動靜能量
@Jian Lin: Yes, to initially generate a Rails application you need to have the Rails gem installed without using Bundler. To run a Rails project however you only need it installed as a bundled gem.
Ryan Bigg
A: 

your procedure seems correct (be sure to use the newly created gemset too, verify by rvm info, do rvm ree@proj if it doesn't say gemset: 'proj' ), so I'll stick my head out and try a suggestion. Btw, rails installs perfectly with bundler.

I've been struggling with wierd behaviour system gems vs local gems, as have a lot of bundler users, including Yehuda Katz, leading to this comprehensive post A Tale of Abort Traps

In short, if you run bundle install before you have the bundler gem (getting the "standard" gem not found error), then do gem install bundler, followed by another bundle install, the bundler gem has been install to your system, not rvm.

Solution: Delete .bundle, (and do gem uninstall bundler?). Then I would open a new term, do rvm ree@proj, and gem install bundler prior to bundle install.

Yehuda says in the post that it is fixed in new bundler versions, but I experienced this just a few days ago (bundler 1.0.0). Hope I brought more help than confusion to the table :)

Ole Morten Amundsen