Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does RVM install duplicate gems for different gemsets?

Tags:

ruby

rvm

bundler

So, I've created a separate rvm gemset for each of my rails projects. They both use the same version of ruby 1.9.3.

This causes bundle install to completely install a fresh set of gems for both projects. It doesn't matter if the other project has the exact same version of the gem installed in the other gemset. I'm guessing this is the expected behavior to me but it seems like an inefficient use of hard drive space and bandwidth.

I know that I could manually move some of those gems to a global gemset, but that seems tedious to me and also prone to breaking if my dependencies change for a particular project.

Is there a better way to organize things, or have rvm auto detect when a gem version is already installed and just use that copy?

Or is there a better alternative to RVM that I should be using.

like image 532
Christian Schlensker Avatar asked Jun 04 '12 19:06

Christian Schlensker


People also ask

What is RVM gemset?

Named Gem Sets RVM gives you compartmentalized independent ruby setups. This means that ruby, gems and irb are all separate and self-contained - from the system, and from each other.

How do I use Gemset?

Assuming that you are already on your project directory. Now run these commands from your CLI. Step 1: rvm gemset create [name of gemset] Step 2: rvm --rvmrc [ruby version here]@[name of gemset] # Note: You can check your current ruby version by running "ruby -v" from your console. Step 3: Refresh your directory.


1 Answers

This is by design. Gemsets allow you to completely isolate the libraries used so you don't have any accidental interaction between projects. If you don't need the isolate you can just use an interpreter without a gemset:

rvm use 1.9.3

If there are a few gems you use across all projects, just switch to the global gemset for the interpreter:

rvm use 1.9.3@global

gem install the common gems and then they won't be re-installed per-project anymore when you are in a gemset.

While gemsets definitely aren't efficient in terms of bandwidth or HD space, they are extremely handy because you can easily blow away all dependencies for a project and re-bundle from scratch any time you want to. They also completely eliminate accidentally changing versions of your dependencies. If you don't like gemsets, correctly specifying versions in your Gemfile can get you pretty far on this without them.

As far as alternatives, rbenv is the main one I'd check out.

like image 147
Matt Sanders Avatar answered Sep 28 '22 04:09

Matt Sanders