Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are we installing Ruby 1.9.2/1.9.3 gems into a 1.9.1 folder?

Tags:

ruby

rubygems

This comes about because the Gem installation directory used by the gem command, seen when using gem env, is set to something like:

<base_ruby_dir>/lib/ruby/gems/1.9.1

My question is why?

Shouldn't the folder be called:

<base_ruby_dir>/lib/ruby/gems/1.9.x

or

<base_ruby_dir>/lib/ruby/gems/1.9

or else couldn't there be one per version of Ruby, like:

c:/ruby191/lib/ruby/gems/1.9.1
c:/ruby192/lib/ruby/gems/1.9.2
c:/ruby193/lib/ruby/gems/1.9.3

Not a critical problem I know, I was just wondering.

like image 437
Ben Avatar asked Dec 19 '11 16:12

Ben


People also ask

Where does Ruby install gems to?

Once you've required ap , RubyGems automatically places its lib directory on the $LOAD_PATH . That's basically it for what's in a gem. Drop Ruby code into lib , name a Ruby file the same as your gem (for the gem “freewill” the file should be freewill. rb , see also name your gem) and it's loadable by RubyGems.

What is gem install?

gem install , in its simplest form, does something kind of like this. It grabs the gem and puts its files into a special directory on your system. You can see where gem install will install your gems if you run gem environment (look for the INSTALLATION DIRECTORY: line):

How do you check if a gem is installed?

Since your goal is to verify a gem is installed with the correct version, use gem list . You can limit to the specific gem by using gem list data_mapper . To verify that it's installed and working, you'll have to try to require the gem and then use it in your code.


1 Answers

In Ruby 1.9.0, the C interface was changed from the Ruby 1.8 series.

Gems that compile to native code had to be recompiled.

The interface was again changed in Ruby 1.9.1 and kept the same in Ruby 1.9.2 & 3. This explains the 1.9.1 you are seeing in your path.

The idea is that you can install different versions of Ruby on your system and that gems would be shared within groups having the same C api. So Ruby 1.8.6 and 1.8.7 could share their gems, and so could Ruby 1.9.1, .2 and .3.

It's not necessarily the best idea, though. In any case, most people use rvm to access different versions of Ruby and rvm keeps gems separate for each version, irrespective of the C api version.

like image 150
Marc-André Lafortune Avatar answered Sep 25 '22 16:09

Marc-André Lafortune