Bundler VS Rvm VS Gems VS Rubygems VS Gemsets VS System Ruby

bundler vs RVM vs gems vs RubyGems vs gemsets vs system ruby

As per the previous answer, this is quite a lot to cover, so consider this a short introduction.

gems are the way Ruby libraries are packaged. They are to Ruby what jars are to Java. Inside a gem file, you find Ruby code (.rb files), but also tests, and a special file giving information on the gem itself, such as its name, dependencies and version (gemspec). Any Ruby project can define the gems it needs via a Gemfile that just need to declare dependencies. Rubygems is the name of the package manager - the tool used to install the packages (while the gems are the packages themselves). Rubygems is now part of Ruby.

Bundler is what makes managing gems bearable. Based on your Gemfile, a simple call to bundler using bundle install will download and install all the required gems. Using standard gem command, you would have to install each of them manually, using gem install <gem_name>. Bundler is not part of Ruby (it is itself packaged as a gem), but it a "de facto standard" for most applications (you will not find many people not using it, and no good reasons not to use it, actually).

RVM is a tool allowing you to install multiple versions of Ruby on a machine, switching between them when needed. This can be used to install both a Ruby 1.8 and 1.9, or even a "MRI" (Matz's Ruby, the default implementation) and alternatives (such as JRuby or Rubinius). Note that RVM is not alone in this field, see for instance rbenv.

A gemset in RVM is a set of gems specific to a given context, typically a project. This is useful if you are for example developing different applications, each with its own sets of gems, and want to keep them separate.

system Ruby is, when using RVM, the Ruby version installed on the machine (ie, not via RVM).

If you are just starting, gems and bundler are of interest to you. You can let RVM and gemsets aside for now.

System ruby/gem vs RVM ruby/gem

  1. Yes. Use bundler and there will be no pain.
  2. It just need to be run in RVM environment. No special porting required.
  3. It is intended to provide separate environment for each of your projects by substituting environment variables like $PATH, $GEM_HOME, $GEM_PATH.

Pros:

  1. You can have different ruby interpreters installed to fulfil your applications' requirements. Imagine that you are starting a new project with Rails 1.9.3, but you are still working on old two which use 1.8.7 and 1.9.1 and have not been ported so far.
  2. Your gems does not conflict with each other. For example Psych has special needs. If you use it, you got to use it in all your project. But with RVM you can create different gemsets for each project.
  3. Moves gem directories too dirs where you got read+write access. This is good because does not force you to compile gems with root privileges.

Cons:

  1. I had problems with RVM when using it for long time under Fish shell. Two times, after some weeks whole RVM went crazy and just get broken. Not going into details, I got to remove whole ~/.rvm directory. Never happened under Bash.

My typical workflow with RVM is following:

  1. Add ruby "1.9.3" or equivalent to Gemfiles of my projects to avoid running it with wrong Ruby version.
  2. Install RVM and install Rubies I need, rvm install 1.9.3.
  3. In given project, rvm use 1.9.3.
  4. Install required gems.
  5. Use my app normally.

Please note I am not using Gemsets. This is because of Cons #1. I really love Fish shell, can't live without it, and bundler alone gives me decent management of Gems (one problem: Psych). To use Gemsets, two additional steps between 3. and 4.:

3a. Create one rvm gemset create gemset1.

3b. Use it rvm use gemset1@1.9.3.

I always use RVM when working with some legacy projects.

Refer to this screencast: http://railscasts.com/episodes/200-rails-3-beta-and-rvm for decent tutorial.

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

Is there a difference between using RVM local gemset and using Bundle exec?

If you're an RVM fan like myself, I would go with creating my own gemset for every rails project I start. This will make it easier for me to just use rake and rails commands without specifying bundle exec every time.

Put in mind when sharing your code that some developers might be using rbenv or maybe not using a ruby version manager at all. One way you can make sure that everyone is happy and working with the same version of ruby, is to provide two additional files in your project directory (.ruby-version and .ruby-gemset) and track them in your project.

The .ruby-version file would contain the version of ruby you're using for example 2.4.1. Note that this is compatible with both RVM and rbenv and will switch to the correct ruby version.

The .ruby-gemset file is identified only by RVM; thus, switching to the correct gemset you have setup for the project.

This will make your project compatible with developers using rbenv while still making those of us using RVM happy :)

Putting all these considerations in mind, now you should care less wither people use bundle exec or not!

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.

What is the difference between bundle update and gem update?

The main difference is that Rubygems (invoked with the command gem) manages all the gems (gemsets if you are using RVM) for a single machine, whereas Bundler (bundle) manages a gem set for a single application (its purpose being to deploy on multiple machines).

The Ruby Version Manager (rvm) only eases the task of managing different gem versions on the same machine, but it's not application-related unless you want to name a gemset for a particular application (see named gemsets).

Both will ignore any previously installed gems and resolve all dependencies again based on the latest versions of all gems available in the sources. However Bundler, unlike Rubygems, will only update gems and dependencies specified in the application's Gemfile, complying with its restrictions (version numbers and spermises).

That said, you should use bundle install instead of bundle update, to be sure you are installing the same exact gems and versions across machines.

I'm using RVM, what is the difference between using bundle install and rvm bundle install?

I think from this question, that you've not quite grasped the difference between rvm and bundler and what exactly each does. I'll try and explain the difference.

RVM is an acronym for Ruby enVironment (Version) Manager. It's a set of command-line scripts to help "sandbox" ruby binaries and gems for a project or set of projects. This way if you have one project that requires Ruby 1.8 and another that uses Ruby 1.9, you can switch easily between the two ruby installations and avoid nasty incompatibilities or cumbersome configuration.

You can also install different gemsets with each ruby version, so if you need to develop some applications with Ruby on Rails 2.3 and some with 3.0, or if you want to try the new 3.1 prelease, you can do so without breaking other applications' dependencies.

Bundler is a ruby gem which, as the website says, manages an application's dependencies through its entire life across many machines systematically and repeatably.

Bundler makes it easy to copy one application's source from one machine to another and install all the gems and dependencies needed by that particular application quickly and (relatively) painlessly.

So I understand the confusion as there is a bit of overlap. RVM gemsets are similar to gem bundles. The difference is that bundler manages the gems and dependencies for a single application and across multiple machines. An rvm gemset is a sandbox that keeps a group of gems in one place, tied to a particular ruby installation on a single machine, sometimes used for multiple applications.

So to close, when you say you "loaded up an rvm project" in your IDE, that's not particularly true. RVM is a sandbox, not a framework.

Rubygems, Bundler and RVM confusion

  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.


Related Topics



Leave a reply



Submit