Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relationships between Rubygems, Bundler, and RVM

Following current best practices, what is the proper role for each of these?

Based on my limited understanding of Bundler and RVM, it seems that they--like Rubygems--have their own install locations for gems. Plus, for each one, there's the option of installing to system paths using sudo or to your home directory. And then there's the ability to vendor gems with Bundler (where applicable, e.g. with Rails).

So it looks to me like there are at least seven places to install gems now:

  • Rubygems system path
  • Rubygems user path
  • RVM system path
  • RVM user path
  • Bundler system path
  • Bundler user path
  • Vendor (per-app)

So, what's the best way to manage all this? Do we use all three (Rubygems, Bundler, RVM) and tell them all to install gems to the same place? Do we use sudo all the time, some of the time, or never? And should we be using a different strategy on production and development machines?

On a related note, are Bundler and RVM wrappers around Rubygems, are they alternatives to it, or are they completely orthogonal to it?

like image 278
rlkw1024 Avatar asked Dec 05 '10 22:12

rlkw1024


People also ask

What is RubyGems bundler?

Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. Bundler is an exit from dependency hell, and ensures that the gems you need are present in development, staging, and production. Starting work on a project is as simple as bundle install .

What is the difference between Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.

Is bundler part of Ruby?

As of Ruby 2.6. 0preview3, Bundler is part of core Ruby.

How does bundler work in Rails?

Think of bundler as a package management tool. So bundle install command will install all gems to the system that are listed in Gemfile as well as their dependencies. If the gem was not previously installed it will grab it from the gemcutter repo.


1 Answers

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

like image 143
PerfectlyNormal Avatar answered Oct 12 '22 21:10

PerfectlyNormal