# LoadError: no such file to load

**URL:** <https://rubytalk.org/t/loaderror-no-such-file-to-load/42010>\
**Category:** ruby-talk\
**Created:** [8 November 2007 07:33 UTC](https://rubytalk.org/t/loaderror-no-such-file-to-load/42010 "2007-11-08T07:33:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Hug](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Peter\_Hug](https://rubytalk.org/u/Peter_Hug)\
**Post date:** [8 November 2007 07:33 UTC](https://rubytalk.org/t/loaderror-no-such-file-to-load/42010/1 "2007-11-08T07:33:25Z")

</div>

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-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Axel\_Etzold](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@Axel\_Etzold](https://rubytalk.org/u/Axel_Etzold)\
**Post date:** [8 November 2007 07:50 UTC](https://rubytalk.org/t/loaderror-no-such-file-to-load/42010/2 "2007-11-08T07:50:51Z")

</div>

-------- 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-forum.com/\](http://www.ruby-forum.com/%5C).

Dear Pete,

try

require "rubygems"  
require "json"

. This should work.

Best regards,

Axel

> **···**
>
> --  
> Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten  
> Browser-Versionen downloaden: [GMX Browser - verwenden Sie immer einen aktuellen Browser. Kostenloser Download.](http://www.gmx.net/de/go/browser)

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [25 November 2012 09:17 UTC](https://rubytalk.org/t/loaderror-no-such-file-to-load/42010/3 "2012-11-25T09:17:29Z")

</div>

Peter Hug 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!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Peter\_Hug](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Peter\_Hug](https://rubytalk.org/u/Peter_Hug)\
**Post date:** [8 November 2007 19:59 UTC](https://rubytalk.org/t/loaderror-no-such-file-to-load/42010/4 "2007-11-08T19:59:20Z")

</div>

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-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Arlen\_Christian\_Mar1](https://avatars.discourse-cdn.com/v4/letter/a/9de053/32.png) [@Arlen\_Christian\_Mar1](https://rubytalk.org/u/Arlen_Christian_Mar1)\
**Post date:** [9 November 2007 10:49 UTC](https://rubytalk.org/t/loaderror-no-such-file-to-load/42010/5 "2007-11-09T10:49:28Z")

</div>

Hi,

> 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

> **···**
>
> On Fri, 2007-11-09 at 04:59 +0900, Peter Hug wrote:

---

<div class="post-metadata">

**Author:** ![A\_LeDonne](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@A\_LeDonne](https://rubytalk.org/u/A_LeDonne)\
**Post date:** [9 November 2007 18:52 UTC](https://rubytalk.org/t/loaderror-no-such-file-to-load/42010/6 "2007-11-09T18:52:27Z")

</div>

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

> **···**
>
> 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
