# IRB not finding "rubygems"

**URL:** <https://www.ruby-forum.com/t/irb-not-finding-rubygems/141327>\
**Category:** Ruby\
**Created:** [June 24, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/irb-not-finding-rubygems/141327 "2008-06-24T18:30:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [June 24, 2008, 6:30pm UTC](https://www.ruby-forum.com/t/irb-not-finding-rubygems/141327/1 "2008-06-24T18:30:03Z")

</div>

This an odd one.

require ‘rubygems’

works in my scripts . . . but if I go to IRB to test some ‘rspec’ stuff.  
I get:

> > require ‘rubygems’  
> > =\> false

Tried including the whole path, but that did not work either any ideas  
why scripts being run don’t have a problem requiring rubygems but IRB  
does?

OSX 10.5.3  
Ruby 1.8.6  
Model Name: MacBook Pro 15"  
Model Identifier: MacBookPro1,1  
Processor Name: Intel Core Duo  
Processor Speed: 2.16 GHz  
Number Of Processors: 1  
Total Number Of Cores: 2  
L2 Cache: 2 MB  
Memory: 2 GB

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [June 24, 2008, 6:40pm UTC](https://www.ruby-forum.com/t/irb-not-finding-rubygems/141327/2 "2008-06-24T18:40:11Z")

</div>

On Tuesday 24 June 2008, Brad Hutchins wrote:

> Processor Name: Intel Core Duo  
> Processor Speed: 2.16 GHz  
> Number Of Processors: 1  
> Total Number Of Cores: 2  
> L2 Cache: 2 MB  
> Memory: 2 GB

The value returned by require doesn’t tell whether there was an error or  
not  
(if the file can’t be found, a LoadError exception will be raised).  
Rather,  
since require tries to avoid loading a file more than one time, it says  
whether you required the file for the first time (true) or if it had  
already  
been loaded (in this case returns false and doesn’t try to load the file  
again). So, the fact that in irb

require ‘rubygems’

returns false only means that the file rubygems.rb had already been  
loaded,  
and it wasn’t necessary to load it a second time.

Stefano

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [June 24, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/irb-not-finding-rubygems/141327/3 "2008-06-24T18:42:32Z")

</div>

El Martes, 24 de Junio de 2008, Brad Hutchins escribiÃ³:

> > > require ‘rubygems’  
> > > =\> false

When you get “false” it means that library was **already** loaded.  
Example:

~$ irb  
irb(main):001:0\> require ‘time’  
=\> true  
irb(main):002:0\> require ‘time’  
=\> false

If the library doesn’t exist in the configured path you would get an  
error:

irb(main):001:0\> require ‘non\_existing\_library’  
LoadError: no such file to load – non\_existing\_library  
from (irb):1:in `require’  
from (irb):1  
from :0

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [June 24, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/irb-not-finding-rubygems/141327/4 "2008-06-24T18:59:20Z")

</div>

Stefano C. wrote:

> On Tuesday 24 June 2008, Brad Hutchins wrote:
> 
> > Processor Name: Intel Core Duo  
> > Processor Speed: 2.16 GHz  
> > Number Of Processors: 1  
> > Total Number Of Cores: 2  
> > L2 Cache: 2 MB  
> > Memory: 2 GB
> 
> The value returned by require doesn’t tell whether there was an error or  
> not  
> (if the file can’t be found, a LoadError exception will be raised).  
> Rather,  
> since require tries to avoid loading a file more than one time, it says  
> whether you required the file for the first time (true) or if it had  
> already  
> been loaded (in this case returns false and doesn’t try to load the file  
> again). So, the fact that in irb
> 
> require ‘rubygems’
> 
> returns false only means that the file rubygems.rb had already been  
> loaded,  
> and it wasn’t necessary to load it a second time.
> 
> Stefano

Hmmm . . . then I have a different problem.

on to requiring rspec

Bulk updating Gem source index for: [http://gems.rubyforge.org](http://gems.rubyforge.org)  
Updating metadata for 13 gems from [http://gems.rubyonrails.org](http://gems.rubyonrails.org)  
…  
complete  
Successfully installed rspec-1.1.4  
1 gem installed  
Installing ri documentation for rspec-1.1.4…  
Installing RDoc documentation for rspec-1.1.4…  
macbook-pro-15:~ $ irb

> > require ‘rspec’

LoadError: no such file to load – rspec  
from  
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require’  
from (irb):1

> >

And this is the second time I have unistalled and re-installed rspec.

Tested other GEMs . . .

> > require ‘snmp’  
> > true

---

<div class="post-metadata">

**Author:** ![bhutchins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f1d935/32.png) [@bhutchins](https://www.ruby-forum.com/u/bhutchins)\
**Post date:** [June 24, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/irb-not-finding-rubygems/141327/5 "2008-06-24T20:26:51Z")

</div>

On Tuesday 24 June 2008, Brad Hutchins wrote:

> > not  
> > returns false only means that the file rubygems.rb had already been  
> > Updating metadata for 13 gems from [http://gems.rubyonrails.org](http://gems.rubyonrails.org)  
> > LoadError: no such file to load – rspec  
> > from  
> > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rub  
> > ygems/custom\_require.rb:27:in `gem_original_require' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rub ygems/custom_require.rb:27:in `require’  
> > from (irb):1

That’s because rspec doesn’t provide a rspec.rb file but a spec.rb file.  
So

require ‘spec’

should work.

Stefano
