[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

LoadError: no such file to load

Peter Hug

11/8/2007 7:33:00 AM

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
--
Posted via http://www.ruby-....

4 Answers

Axel Etzold

11/8/2007 7:51:00 AM

0


-------- Original-Nachricht --------
> Datum: Thu, 8 Nov 2007 16:33:25 +0900
> Von: Peter Hug <pete@kapiti.co.nz>
> An: ruby-talk@ruby-lang.org
> Betreff: 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
> --
> Posted via http://www.ruby-....


Dear Pete,

try

require "rubygems"
require "json"

This should work.

Best regards,

Axel
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/...

Peter Hug

11/8/2007 7:59:00 PM

0

Axel Etzold 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
--
Posted via http://www.ruby-....

Arlen Cuss

11/9/2007 10:49:00 AM

0

Hi,

On Fri, 2007-11-09 at 04:59 +0900, Peter Hug wrote:
> Axel Etzold 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?

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


Alex LeDonne

11/9/2007 6:52:00 PM

0

On Nov 8, 2007 2:59 PM, Peter Hug <pete@kapiti.co.nz> wrote:
> Axel Etzold 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

The Ruby One-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