LoadError: no such file to load

This happens on a i486 Ubuntu 7.04 machine. If I do:

gem list --local

I get a list of installed gems. However, if I then try to load any of
these gems like for example the (json gem) as follows:

require ‘json’

I get a LoadError: no such file to load. I have worked out where for
example the json gem resides and then I navigated to that directory and
used irb to test if require ‘json’ would work from there and it seemed
fine (returned true).

It appears to me that ruby doesn’t know the path to gems, how can I fix
this?

Pete

-------- Original-Nachricht --------

Datum: Thu, 8 Nov 2007 16:33:25 +0900
Von: Peter H. [email protected]
An: [email protected]
Betreff: LoadError: no such file to load

example the json gem resides and then I navigated to that directory and
used irb to test if require ‘json’ would work from there and it seemed
fine (returned true).

It appears to me that ruby doesn’t know the path to gems, how can I fix
this?

Pete

Posted via http://www.ruby-forum.com/.

Dear Pete,

try

require “rubygems”
require “json”

. This should work.

Best regards,

Axel

Axel E. wrote:

require “rubygems”
require “json”

Spot on Axel, that fixed it! Thanks heaps.

What puzzles me though is that the same setup works fine under Windows
(i.e. my ruby scripts can use any installed gems without having to load
rubygems first.

Any idea why that would be?

Pete

Hi,

On Fri, 2007-11-09 at 04:59 +0900, Peter H. wrote:

Any idea why that would be?
Your Windows installation probably automagically includes the gem path
in Ruby’s search path (perhaps the installation you have includes some
gems, and so puts that in for you).

Try this:
irb(main):001:0> $:
=> ["/usr/local/lib/site_ruby/1.8",
“/usr/local/lib/site_ruby/1.8/x86_64-linux”, “/usr/local/lib/site_ruby”,
“/usr/lib/ruby/1.8”, “/usr/lib/ruby/1.8/x86_64-linux”, “.”]
irb(main):002:0>

You can see what paths are included in the search. You should always
require ‘rubygems’ before requiring anything you expect may be in a gem,
though, for maximum cross-compatibility.

Pete

Cheers,
Arlen

On Nov 8, 2007 2:59 PM, Peter H. [email protected] wrote:

Any idea why that would be?

Pete

The Ruby O.-Click Installer sets an environment variable calld
RUBYOPT to -rubygems, which causes ruby to automatically require
‘rubygems’ for you.

You could set RUBYOPT on your Ubuntu box, if you like.

-A

Peter H. wrote in post #583719:

This happens on a i486 Ubuntu 7.04 machine. If I do:

gem list --local

I get a list of installed gems. However, if I then try to load any of
these gems like for example the (json gem) as follows:

require ‘json’

I get a LoadError: no such file to load. I have worked out where for
example the json gem resides and then I navigated to that directory and
used irb to test if require ‘json’ would work from there and it seemed
fine (returned true).

It appears to me that ruby doesn’t know the path to gems, how can I fix
this?

Pete

require ‘rubygems’
require ‘json’

works for me!