1

I think I've got myself into a bit of a mess and I'd like some pointers in cleaning it up. I have RVM installed and Ruby 2.2.3 (that's the only version):

rvm list
rvm rubies
=* ruby-2.2.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

I've only got the basic gemsets:

rvm gemset list

gemsets for ruby-2.2.3 (found in /Users/Andrew/.rvm/gems/ruby-2.2.3)
=> (default)
   global

If I look at a snipped directory structure I have:

~/.rvm/gems/ruby-2.2.3
~/.rvm/gems/ruby-2.2.3@global

If I run gem env, my paths are:

[..snip..]
  - GEM PATHS:
     - /Users/Andrew/.rvm/gems/ruby-2.2.3
     - /Users/Andrew/.rvm/gems/ruby-2.2.3@global
[..snip..]
  - SHELL PATH:
     - /Users/Andrew/.rvm/gems/ruby-2.2.3/bin
     - /Users/Andrew/.rvm/gems/ruby-2.2.3@global/bin
[..snip..]

To the best of my knowledge, the gems in ruby-2.2.3 are up to date but the ones in ruby-2.2.3@globabl aren't.

In IntelliJ IDEA, I have references to SDK for ruby-2.2.3 and ruby-2.2.3[Global]. In the Global gems directory it lists the gems for ruby-2.2.3[global] and I can some of these are at a different version to the gems for ruby-2.2.3.

I've researched quite a lot via google but I'm still confused on how to get the gems in ruby-2.2.3@globabl upgraded and whether I need to. I can't tell the relationship between these gems and the gemsets for which default is empty and global has around 4 gems listed.

I'm thinking I could do gem clean to get rid of older gem versions (but I've read in a number of places that's dangerous) but that wouldn't upgrade ruby-2.2.3@global. I'm also concerned it might screw up my IntelliJ Idea environment which I'm also struggling to get my head around!

What I'd like to do is this:

  • Understand the relationship between the gems in the paths ruby-2.2.3, ruby-2.2.3@global
  • Understand the relationship between these gems and the gemsets default and global (if any). My understanding is that gemsets should be created for each project with those gems defined in
    Global available to all. Then I get confused between these and
    Bundler!
  • How to upgrade the gems in path ruby-2.2.3@global
  • How to cleanup and get rid of older gems safely. Particularly, without screwing up IntelliJ Idea

I haven't found an easy noob guide to all this. Perhaps the easiest thing to do is an rvm implode and start again? I'm trying to learn ruby, ruby on rails, rspec.

ad-johnson
  • 555
  • 3
  • 17
  • `bundle clean` with `--force` option. – Andrey Deineko Dec 06 '15 at 18:15
  • 1
    rvm gemset use global; gem update ; gem cleanup. Global are gems that are available in all gemsets per ruby version. Default are gems That you want installed in each ruby version. – Doon Dec 06 '15 at 19:13
  • so if i use rvm gemset use global...that will mean the update will apply to gems in ~/.rvm/gems/ruby-2.2.3@global? How then do I switch back - rvm gemset default? – ad-johnson Dec 06 '15 at 19:26
  • ` rvm ruby-2.2.3` will go back to the normal version without the gemset selected. not sure if the exact way to do it , but it has always worked for me – Doon Dec 07 '15 at 18:49
  • after doing some more digging, i've added an answer that I think covers your questions.) – Doon Dec 07 '15 at 19:40

1 Answers1

2

Rvm has a global gemset. This gemset allows you to install gems that should be available to every other the gemset you create for a given version of ruby you have installed in rvm.

for example you have ruby-2.2.3 installed and you have the following gemsets created. project1, project2. Both projects use bundler so as opposed to having 2 copies, you can install it in the @global gemset (see https://rvm.io/gemsets/global/ )

rvm @global do gem install bundler

to update the gems you can do

rvm @global do gem update

or to see which gems are there

rvm @global do gem list

now if you create gemset project3, the bundler gem will already be installed for you.

If you install a different ruby say 1.8.7, then none of your gems in that global will be available, since they are only global to 2.2.3.

If you would like to always have certain gems installed in all of your rubies, you can look at the initialization files. These files are located in ~/.rvm and consist of global.gems and default.gems. (see https://rvm.io/gemsets/initial ).

Gems in ~/.rvm/global.gems will be installed when you install a new ruby, and be used to populate the global gemset for that ruby. ~/.rvm/default.gems is the same, save they will go into the default/blank gemset that rvm creates. The caveat at the bottom of that page should be headed as by default they are overwritten when you upgrade rvm.

Bundler is a completely different beast, and came around after rvm had gemsets, and it solves a similar problem. Before bundler (and gemsets) it was easy to run into dependency hell. Where one project used version x of a gem, and another used version y, so you needed to have both installed, but which one got activated, etc always caused issues. So when rvm came around, you could create gemsets to keep each projects gems separate from each other. Then bundler came into exisitance which let you do roughly the same thing with the use of a Gemfile. So if all of your projects are using bundler, you can totally get away without using per project gemsets, as you just install all your gemsets in your default gemset, and let bundler due the dependency management.

Doon
  • 19,719
  • 3
  • 40
  • 44
  • That is excellent information Doon, thanks. It's actually cleared up a lot of queries I had in my head about how these things interacted. Thank you very much. Just to add: I did up vote your answer but I don't have enough points yet for it to show. – ad-johnson Dec 08 '15 at 14:18