Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RVM Gemsets and Ruby Gemfile confusion

Someone please help me understand how a ruby app manages both the gemfile and the rvm gemsets for an app. If i am currently using a Gemset, with a bunch of installed gems, and i also have gems in my gemfile, is the Ruby app using the gems from the gemfile or from the gemset for the app?

like image 354
Josh C Avatar asked May 21 '15 21:05

Josh C


1 Answers

To understand this you need to step back and understand how ruby gems work in general.
Let's start with a system that does not have rvm or a Gemfile.
When you install a gem via "gem install" it goes into the system gem location.
Whenever you write a ruby script and require the gem it will be picked up from there.

Now suppose you need to use different version of a gem for different projects. This is where bundler comes in. You create a Gemfile and when you "bundle install" the gems listed in the Gemfile will be brought in and be used in the context of that project. You will need to do "bundle install" to bring them in and after that "bundle exec ruby" to run with the gem version. You can have multiple gem versions and pick an choose which one to use. If you don't go through bundler you will use whatever is in the system.

Rvm now. Suppose you want to alter the "system" gems and ruby versions in an organized way. This is basically what an rvm gemset is. by the magic of indirection via paths, you can install gems for different gem sets and pretend they are system gems.

So gemsets and gemfiles are orthogonal on each other. if you use a gem file the gems will be installed in the gem set, but you usually don't care about that if you go though bundler.

Normally you would want to use the Gemfile.

like image 99
Mircea Avatar answered Oct 15 '22 20:10

Mircea