Solved: Ruby Gem Require LoadError (8-STABLE, Ruby 1.9.1)

Aaron Gifford astounding at
Fri Jan 29 04:50:41 UTC 2010

On Thu, Jan 28, 2010 at 7:25 PM, Aaron Gifford <astounding at> wrote:
>  I wrote:
>> One more interesting thing:
>> % ruby19 -e 'p Gem.default_dir'
>> "/usr/local/lib/ruby19/gems/1.9"
>> That is NOT right.  It should be "/usr/local/lib/ruby/gems/1.9" instead.
>> Where does Gem.default_dir get set, does anyone know?
>> Aaron out.
> It looks like gem_prelude.rb sets up the gems include path.
> The relevant code section is:
>  def self.default_dir
>        File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
>                  ConfigMap[:ruby_version]
>      elsif RUBY_VERSION > '1.9' then
>        File.join(ConfigMap[:libdir], ConfigMap[:ruby_install_name], 'gems',
>                  ConfigMap[:ruby_version])
>      else
>        File.join(ConfigMap[:libdir], ruby_engine, 'gems',
>                  ConfigMap[:ruby_version])
>      end
>    end
> So the Gem.default_dir is being set to:
>  File.join(ConfigMap[:libdir], ConfigMap[:ruby_install_name], 'gems',
> ConfigMap[:ruby_version])
> (that's the middle "RUBY_VERSION > '1.9'" code chunk)
> So ConfigMap[:ruby_install_name] is "ruby19" in this case, and THAT's
> what is screwing this up.
> Either the FreeBSD Ruby 1.9 port needs to install things in
> "/usr/local/lib/ruby19" instead of "/usr/local/lib/ruby/" so the code
> will work as-is, or else something's gotta change with
> ConfigMap[:ruby_install_name], or else gem_prelude.rb code has to be
> changed...
> So... anyone with expertise, where does one go from here?
> Aaron out.

It looks like ConfigMap[:ruby_install_name] gets set earlier in the
same gem_prelude.rb code to RbConfig::CONFIG["ruby_install_name"]
which in turn is set in rbconfig.rb which sets it to "ruby19".  That
file is autogenerated during the build process by the mkconfig.rb
script which gets passed an "install_name" variable setting I'm

That in turn gets set during make.  The Makefile shows:
$(RBCONFIG): $(srcdir)/mkconfig.rb config.status $(PREP)
        @$(MINIRUBY) $(srcdir)/mkconfig.rb -timestamp=$@ \
                -install_name=$(RUBY_INSTALL_NAME) \
                -so_name=$(RUBY_SO_NAME) rbconfig.rb

So it's getting set to the RUBY_INSTALL_NAME value 'ruby19'.  Of
course Makefile is created from the template by the GNU
Autoconf configure process.  The template shows
RUBY_INSTALL_NAME getting set to:


That explains completely how Gem.default_dir is getting set to
""/usr/local/lib/ruby19/gems/1.9" instead of the actual path

ONE POSSIBLE FIX is this patch to gem_prelude.rb (in
--- gem_prelude.rb.orig	2010-01-28 21:22:27.307910440 -0700
+++ gem_prelude.rb	2010-01-28 21:22:43.177946726 -0700
@@ -116,7 +116,7 @@
         File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
       elsif RUBY_VERSION > '1.9' then
-        File.join(ConfigMap[:libdir], ConfigMap[:ruby_install_name], 'gems',
+        File.join(ConfigMap[:libdir], 'ruby', 'gems',
         File.join(ConfigMap[:libdir], ruby_engine, 'gems',

This works.  Building/installing gems under 1.9.1 (with
RUBY_VERSION=1.9.1 in /etc/make.conf) did not break (still works), but
this time, no LoadErrors during require.  AT LAST!

user at host:/home/user% irb19
irb(main):001:0> require 'net/ssh'
=> true

And that makes ruby19 -e 'p Gem.default_dir' output
"/usr/local/lib/ruby/gems/1.9" like it should.

Aaron out.

More information about the freebsd-ruby mailing list