Why Should I Care About Rvm's Gemset Feature When I Use Bundler

Why should I care about RVM's Gemset feature when I use Bundler?

Why should I care about RVM's Gemset feature when I use Bundler?

You shouldn't.

Well, if you want to, you can care about, of course, so I should better say "You don't need to."

I just listened to a podcast interview with one of the Bundler core team members who basically said that since he started using Bundler he stopped using Gemsets, because they are redundant.

Here's a blog post that discusses the same issue, with some examples.

Relationships between Rubygems, Bundler, and RVM

From Bundler's website:

Bundler makes it easy to make sure that your application has the dependencies it needs to start up and run without errors.

This means that it's trivial for some other developer, or you on another machine, to get ready to develop further or use it, by running bundle install and you have everything you need to get up and running.

RVM is for managing multiple versions of Ruby on the same machine, and switching between them. Gemsets is a powerful feature RVM provides that isolates gems for one application/library from the rest of your system.

When using RVM and Bundler together, RVM tells Bundler where the gems should go, and Bundler installs them into the RVM-folder.

Both (with regards to gems in RVMs case) use and depend on Rubygems, so they're closest to wrappers.

I, personally, use Bundler and RVM for all my projects. No gemsets, just Bundler to resolve and fix things, which it does without fail. Installing gems is done without sudo, and ends up in the place RVM defines. The default Ruby install on my system is left alone, and nothing is installed to Rubygems system/user path

rbenv or bundler gemset sandboxing?

bundler uses the Gemfile and Gemfile.lock files in, in essense, to make a "gemset" for that particular project that you access via commands prefixed with bundle exec

rvm, associate a gemset to a project

In the directory of your Rails app add a file called .rvmrc with the text rvm gemset use mytestgemset in it.

When you cd into that directory rvm will notify you that it has switched the gemset in use. The first time you need to confirm, afterwards it will switch automatically.

Can chruby and chgems replace rvm's gemset?

I'll take a run at this question since I use Chruby and Chgems. I am on Mac OS X, and I have chruby installed via Homebrew.

In my .bashrc file:

source /usr/local/share/chruby/chruby.sh
chruby ruby-2.0.0-p195

The source line is part of configuration for Chruby.

The second line sets a default version of Ruby for my system (in my case Ruby 2.0.0). Note: As of Chruby 0.3.6 this belongs in .bashrc instead of .bash_profile.

In my .bash_profile:

source /usr/local/share/chruby/auto.sh

This line sets Auto-switching feature in Chruby.

I still have some projects using Ruby 1.9.3 so for those apps I have a .ruby-version file in the root of the app. with one line ruby-1.9.3


When you cd into the directory for your app, type chgems and then you can bundle install and what not. You can confirm things are working by entering gem env

To make my life easier I added .bash_aliases for example:
alias myapp='cd ~/Sites/myapp && chgems'


I have been using these together for several months now and really like the combination and yes from what I can tell Chgems does a great job replicating the gemset feature of RVM. I highly recommend you read the docs for both Chruby and Chgems projects as this is all covered. In your case, you may not want to set a default Ruby and just use .ruby-version to set it for each app.

Bundler downloads gems present on the system?

Bundler doesn't go re-fetch gems unless one of these things is true:

  • You don't have the same gem and the same version (or allowed range of versions) installed.
  • You are using RVM and different gemsets for different projects and not placing them inside a global gemset.
  • The gem paths are not in the search path Bundler uses.

If this is an issue for you, you can use --local as you know to force Bundler never to even look for anything else, but you can also specify the versions for all your gems. And make sure the right version is in Gemfile.lock.

In the end, Bundler only does what you tell it to do. Of course, you can also not use Bundler.



Related Topics



Leave a reply



Submit