# Gem query finds gem, yet require fails

**URL:** <https://www.ruby-forum.com/t/gem-query-finds-gem-yet-require-fails/75704>\
**Category:** Ruby\
**Created:** [November 12, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/gem-query-finds-gem-yet-require-fails/75704 "2006-11-12T15:30:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [November 12, 2006, 3:30pm UTC](https://www.ruby-forum.com/t/gem-query-finds-gem-yet-require-fails/75704/1 "2006-11-12T15:30:01Z")

</div>

I’m setting up a secondary machine to run tests. I’ve run into a  
problem with gems not being found. Everything works fine on my  
primary machine, and I haven’t been able to tease out what the  
difference is in the two setups.

I’ve installed Ruby 1.8.5 and rubygems 0.9.0, both from source, on  
Mac OS X 10.4.8.  
Ruby configuraiton:  
$ ./configure --prefix=/usr/local

rubygems installation:  
$ sudo /usr/local/bin/ruby setup.rb

I installed the PostgreSQL bindings gem using:  
$ sudo gem install postgres

The bindings appeared to install correctly. Using gem query, I can see:

\*\*\* LOCAL GEMS \*\*\*

postgres (0.7.1)  
The extension library to access a PostgreSQL database from Ruby.

sources (0.0.1)  
This package provides download sources for remote gem installation

However, when testing with irb to see if the postgres gem can be  
found, I get:

$ which ruby  
/usr/local/bin/ruby  
$ which irb  
/usr/local/bin/irb  
$ irb  
irb(main):001:0\> require ‘rubygems’  
=\> true  
irb(main):002:0\> require ‘postgres’  
LoadError: no such file to load – postgres  
from /usr/local/lib/ruby/site\_ruby/1.8/rubygems/  
custom\_require.rb:27:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `require’  
from (irb):2

I’m stumped. On my primary machine, the above two commands work just  
fine in irb.

Looking around custom\_require.rb and seeing the private init\_gemspecs  
method, I tried:  
irb(main):006:0\> gs = Gem::GemPathSearcher.new  
…  
irb(main):017:0\> pp gs.send(:init\_gemspecs)

I can see the postgres gem included in the list (relevant part of the  
output is posted below).

However, the find method fails:

irb(main):018:0\> gs.find(‘postgres’)  
=\> nil

The default dir appears to be correct:

irb(main):020:0\> Gem.default\_dir  
=\> “/usr/local/lib/ruby/gems/1.8”

In the shell:  
$ ls -la /usr/local/lib/ruby/gems/1.8  
total 4040  
drwxr-xr-x 7 root wheel 238 Nov 12 22:11 .  
drwxr-xr-x 3 root wheel 102 Nov 12 22:10 …  
drwxr-xr-x 11 root wheel 374 Nov 12 22:24 cache  
drwxr-xr-x 10 root wheel 340 Nov 12 22:24 doc  
drwxr-xr-x 11 root wheel 374 Nov 12 22:24 gems  
-rw-r–r-- 1 root wheel 2066469 Nov 12 22:12 source\_cache  
drwxr-xr-x 11 root wheel 374 Nov 12 22:24 specifications

Any help would be appreciated. I’ve been staring at this for quite a  
while now and nothing new is coming to me. I don’t have any GEM\_\*  
environmental variables or .gemrc files on either machine. Anything  
else I should try or check?

Thanks!

Michael G.  
grzm seespotcode net

### partial init\_gemspecs output

#\<Gem::Specification:0x585ffc  
@authors=[],  
@autorequire=“postgres”,  
@bindir=“bin”,  
@cert\_chain=nil,  
@date=Wed Oct 20 00:00:00 +0900 2004,  
@default\_executable=nil,  
@dependencies=[],  
@email=“removed\_email\_address@domain.invalid”,  
@executables=[],  
@extensions=[“extconf.rb”],  
@extra\_rdoc\_files=[],  
@files=  
[“ChangeLog”,  
“doc”,  
“extconf.rb”,  
“MANIFEST”,  
“postgres-ruby.gemspec”,  
“postgres.c”,  
“README”,  
“README.ja”,  
“sample”,  
“doc/postgres.html”,  
“doc/postgres.jp.html”,  
“sample/losample.rb”,  
“sample/psql.rb”,  
“sample/psqlHelp.rb”,  
“sample/test1.rb”,  
“sample/test2.rb”,  
“sample/test4.rb”],  
@has\_rdoc=false,  
@homepage=“[http://www.postgresql.jp/interfaces/ruby/](http://www.postgresql.jp/interfaces/ruby/)”,

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [November 14, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/gem-query-finds-gem-yet-require-fails/75704/2 "2006-11-14T16:26:49Z")

</div>

On Nov 12, 2006, at 23:28 , Michael G. wrote:

> ```
> This package provides download sources for remote gem installation
> 
> ```
> 
> =\> true  
> irb(main):002:0\> require ‘postgres’  
> LoadError: no such file to load – postgres  
> from /usr/local/lib/ruby/site\_ruby/1.8/rubygems/  
> custom\_require.rb:27:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in`require’  
> from (irb):2
> 
> I’m stumped. On my primary machine, the above two commands work  
> just fine in irb.

Any ideas at all on this? I’m really stuck. Or perhaps how to make  
sure I’ve completely uninstalled Ruby and rubygems so I can maybe try  
installing again?

As an aside, how could I make this message more likely to get a  
response? I seem to have lost my knack.

Thanks for any suggestions on either issue 🙂

Michael G.  
grzm seespotcode net

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [November 14, 2006, 4:56pm UTC](https://www.ruby-forum.com/t/gem-query-finds-gem-yet-require-fails/75704/3 "2006-11-14T16:56:53Z")

</div>

On 11/14/06, Michael G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > postgres (0.7.1)  
> > $ which irb  
> > from (irb):2
> 
> Thanks for any suggestions on either issue 🙂
> 
> Michael G.  
> grzm seespotcode net

Hi,

[I don’t know anything about neither OSX nor postgres gem]

- it seems you have require patched, so gems are in the game. that’s  
fine.
- postgres from the listing seems to have compiled extension. Check  
whether it is indeed compiled - you’ll have postgres.so somewhere in  
the dir. If it’s not there look for info how to setup build  
environment
- check whether the ext is directly in lib or somewhere deeper - i.e.  
require ‘whatever/postgres’
- go there, try require it from the dir where it is without rubygems  
if you can’t the problem is somewhere deeper.

For example, on debian&co you have to have installed build-essential  
package. Without it, the ext won’t be compiled however gem will  
install fine and don’t tell anything.

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [November 15, 2006, 1:26am UTC](https://www.ruby-forum.com/t/gem-query-finds-gem-yet-require-fails/75704/4 "2006-11-15T01:26:31Z")

</div>

On Nov 15, 2006, at 0:55 , Jan S. wrote:

> - it seems you have require patched, so gems are in the game.  
> that’s fine.

Thanks for confirming that. Good to have a second opinion.

> - postgres from the listing seems to have compiled extension. Check  
> whether it is indeed compiled - you’ll have postgres.so somewhere in  
> the dir. If it’s not there look for info how to setup build  
> environment

This is very helpful. I hadn’t thought to check this. I can see that  
there _is_ a postgres.o on the system that works, but it’s missing on  
the system that doesn’t. This gives me something to pursue.

> - check whether the ext is directly in lib or somewhere deeper - i.e.  
> require ‘whatever/postgres’
> - go there, try require it from the dir where it is without rubygems  
> if you can’t the problem is somewhere deeper.
> 
> For example, on debian&co you have to have installed build-essential  
> package. Without it, the ext won’t be compiled however gem will  
> install fine and don’t tell anything.

From the system where it works, the postgres.o file is in the top-  
level of the postgres-0.7.1 directory (i.e., /usr/local/lib/ruby/gems/  
1.8/gems/postgres-0.7.1/postgres.o) so this is probably not a  
problem, but it’s also something for me to check when I figure out  
why the postgres.o file isn’t getting built.

Thanks for the pointers, Jan. This is really helpful, and gives me  
something to work on 🙂

Michael G.  
grzm seespotcode net

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [November 15, 2006, 4:24pm UTC](https://www.ruby-forum.com/t/gem-query-finds-gem-yet-require-fails/75704/5 "2006-11-15T16:24:29Z")

</div>

On 11/15/06, Michael G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > the dir. If it’s not there look for info how to setup build
> 
> Thanks for the pointers, Jan. This is really helpful, and gives me  
> something to work on 🙂

Glad to help. Try googling for other compiled gems’ problems on OSX -  
e.g. mysql, mongrel, rcov, ruby-prof.

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [November 26, 2006, 3:24am UTC](https://www.ruby-forum.com/t/gem-query-finds-gem-yet-require-fails/75704/6 "2006-11-26T03:24:08Z")

</div>

On Nov 15, 2006, at 9:26 , Michael G. wrote:

> missing on the system that doesn’t. This gives me something to pursue.  
> I was able to install the postgres bindings by explicitly calling

sudo ruby extconf.rb --with-pgsql-lib-dir=/usr/local/lib/ --with-  
pgsql-include-dir=/usr/local/include  
sudo make  
sudo make install

Passing those same compilation flags through gem didn’t work and I’m  
not sure why.

sudo gem install postgres – --with-pgsql-lib-dir=/usr/local/lib/ –  
with-pgsql-include-dir=/usr/local/include

No errors were thrown; the source just didn’t get compiled

Thanks again, Jan, for your help!

Michael G.  
grzm seespotcode net
