RVM, RubyGems and Bundler - How gems are installed ?
anand posted this on 18 Jun 2011
Earlier when I started programming using ruby (system ruby), it was all clean. I used to install gems with sudo gem install somegem . Then came rvm and it asked me to install gems without sudo like: gem install somegem. Then came bundler, which asked me to install gems by bundle install.
Since then, I was confused about how things work using these 2 tools on top of ruby. Well, I decided to put an end to that confusion and here is how they work.
When you use
rubygems would install that gem in the place defined by $GEM_HOME environment variable. Now this is the variable that dominates where rvm puts gems in and where bundler puts gems in.
I suppose you are using rvm to manage multiple rubies. When you switch rubies using rvm, the $GEM_HOME variable changes. rvm changes it.
When we use bundler install to manage dependencies, bundler simply call gem install under hood for each of the gems defined in Gemfile. Lets see this in terminal.
First create a new rails project, it comes with a Gemfile.
Lets then create a new gemset for this project and use it
Install bundler and check $GEM_HOME location for any gems installed.
Do a bundle install in this project and check $GEM_HOME again.
~