Why “bundle install” a gem instead of “gem install” for a rails 3 app?

Using bundler instead of gem command to directly install your gems gives you a whole lot of benefits.

In this specific case where you suggest using the gem command to install and adding it later to the Gemfile, bundler will resolve all the dependencies for you when you install a gem, which you might have to manually resolve otherwise.

To give you an example, let’s take the following dependencies:

sunspot_rails
  nokogiri (>= 1.2.0)

webrat
  nokogiri (>= 1.3) 

Both webrat and sunspot_rails gems require different versions of nokogiri as a dependency. If you just use the gem command to install them, it might install both versions of nokogiri or worse complain about version conflicts. Bundler will be wise enough to resolve this dependency conflict and install the right version (say nokogiri 1.3) and make both sunspot_rails and webrat happy!

Sorry about the long explanation. But, hope you get the point! 🙂

And btw you should have a look at this file Gemfile.lock to see what bundler does behind the scenes for you.

Leave a Comment

tech