Rubygems, Bundler and RVM confusion

Ruby on-RailsRubyRubygemsBundlerRvm

Ruby on-Rails Problem Overview


I read "https://stackoverflow.com/questions/4361645/relationships-between-rubygems-bundler-and-rvm" before asking it again.

Well, there are many questions like this, but people who answered say they work with Rubygems, RVM and Bundler, and they have not explained how each of these work in isolation.

I am really confused with how the three work in isolation when we are installing gems. Please do not tell me how you work, which will help me, but I won't learn what is happening when we play with them.

My confusion can be broken down into these questions. Where is a gem installed when:

  1. I just have Rubygems (without RVM or Bundler)?
  2. Rubygems and RVM are installed?
  3. Rubygems, RVM and Bundler are installed?

Please help me understand this stuff with either resources on the web or by your detailed answers.

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

  1. To find out where gems are being installed to, run echo $GEM_HOME in a terminal.
  2. When using RVM, gems are installed into your RVM install as it changes $GEM_HOME. Running echo $GEM_HOME now would show a path into your RVM install.
  3. When Bundler is added to the mix, gems will either be installed in $GEM_HOME, or, if you specify a path when running bundle install will be installed to that path. To find out where a gem is through Bundler you can use bundle show gemname to get its full path.

Solution 2 - Ruby on-Rails

Use gem env to list the gem paths in each context.

Without RVM gem env will report the system gem library paths.

With RVM gem env will report the RVM-managed gem library paths.

Bundler manages application dependencies and installs into the gem library in your environment. If you are using RVM + Bundler, the gems will be installed in the RVM managed gem directories. If you are using it without RVM, bundler will install gems in the system gem directories.

Solution 3 - Ruby on-Rails

I'm also trying to understand how it works. The blog "Advice on using Ruby, RVM, Passenger, Rails, Bundler, … in development" helped me have a better overview.

BTW, it's a translation of a French article, the French version is better.

Solution 4 - Ruby on-Rails

To find the path where a gem is installed use:

gem which gem_name

To find executables (like html2haml) use:

which executable_name

To avoid typing bundle exec html2haml which is recommended by the Bundler team, use my rubygems-bundler gem.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnandView Question on Stackoverflow
Solution 1 - Ruby on-RailsidlefingersView Answer on Stackoverflow
Solution 2 - Ruby on-RailsAditya SanghiView Answer on Stackoverflow
Solution 3 - Ruby on-RailspgrasView Answer on Stackoverflow
Solution 4 - Ruby on-RailsmpapisView Answer on Stackoverflow