# Gem installation oddity

**URL:** <https://www.ruby-forum.com/t/gem-installation-oddity/173951>\
**Category:** Ruby\
**Created:** [August 18, 2009, 5:43pm UTC](https://www.ruby-forum.com/t/gem-installation-oddity/173951 "2009-08-18T17:43:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [August 18, 2009, 5:43pm UTC](https://www.ruby-forum.com/t/gem-installation-oddity/173951/1 "2009-08-18T17:43:55Z")

</div>

I have been totally puzzled by what I think is a misconfiguration of my  
gem environment. I’ve read and looked and experimented and tried to  
solve this. Maybe you can help… Here’s the top level symptom. I install  
a gem, and then do a ‘which’ and gem says it can’t find it:

sudo gem install wxruby  
Successfully installed wxruby-2.0.0-universal-darwin-9  
1 gem installed  
Installing ri documentation for wxruby-2.0.0-universal-darwin-9…  
Installing RDoc documentation for wxruby-2.0.0-universal-darwin-9…  
/opt/local/lib/ruby/gems/1.8$ gem which wxruby  
Can’t find ruby library file or shared library wxruby  
/opt/local/lib/ruby/gems/1.8$

This is not a peculiarity with this particular gem. There are others in  
this odd state too. Here’s some more context:

# GEM ENVIRONMENT

/opt/local/lib/ruby/gems/1.8$ gem environment  
RubyGems Environment:

- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
- INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/local/bin/ruby
- EXECUTABLE DIRECTORY: /opt/local/bin
- RUBYGEMS PLATFORMS:
  - ruby
  - x86-darwin-9

- GEM PATHS:
  - /opt/local/lib/ruby/gems/1.8
  - /Users/pito/.gem/ruby/1.8

- GEM CONFIGURATION:
  - :update\_sources =\> true
  - :verbose =\> true
  - :benchmark =\> false
  - :backtrace =\> false
  - :bulk\_threshold =\> 1000
  - :sources =\> [“[http://gems.rubyforge.org/](http://gems.rubyforge.org/)”,  
“[http://gems.github.com](http://gems.github.com)”]

- REMOTE SOURCES:
  - [http://gems.rubyforge.org/](http://gems.rubyforge.org/)
  - [http://gems.github.com](http://gems.github.com)  
/opt/local/lib/ruby/gems/1.8$

# GEM SPECIFICATION FOR THE GEM IN QUESTION

/opt/local/lib/ruby/gems/1.8$ gem specification wxruby  
— !ruby/object:Gem::Specification  
name: wxruby  
version: !ruby/object:Gem::Version  
version: 2.0.0  
platform: universal-darwin-9  
authors:

- wxRuby development team  
autorequire:  
bindir: bin  
cert\_chain: []

date: 2009-02-26 00:00:00 -05:00  
default\_executable:  
dependencies: []  
… much more …

# OTHER SHELL ENV

/opt/local/lib/ruby/gems/1.8$ echo $PATH  
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

/opt/local/lib/ruby/gems/1.8$ echo $GEMPATH  
/opt/local/lib/ruby/gems/1.8  
/opt/local/lib/ruby/gems/1.8$

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [August 18, 2009, 5:56pm UTC](https://www.ruby-forum.com/t/gem-installation-oddity/173951/2 "2009-08-18T17:56:32Z")

</div>

> /opt/local/lib/ruby/gems/1.8$ gem which wxruby  
> Can’t find ruby library file or shared library wxruby  
> /opt/local/lib/ruby/gems/1.8$

Might be a bug. [GitHub - Pistos/ruby-which: Like the UNIX "which" tool, but for Ruby libraries.](http://github.com/Pistos/ruby-which/tree/master) might  
help temporarily.  
-r

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [August 18, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/gem-installation-oddity/173951/3 "2009-08-18T20:22:56Z")

</div>

On Aug 18, 2009, at 08:43, Pito S. wrote:

> Installing ri documentation for wxruby-2.0.0-universal-darwin-9…  
> Installing RDoc documentation for wxruby-2.0.0-universal-darwin-9…  
> /opt/local/lib/ruby/gems/1.8$ gem which wxruby  
> Can’t find ruby library file or shared library wxruby  
> /opt/local/lib/ruby/gems/1.8$
> 
> This is not a peculiarity with this particular gem. There are others  
> in  
> this odd state too.

Is there even a wxruby in the gem?

gem contents -l wxruby

will tell you if you’ve got the gem installed

You can also check from the .gem file without installing:

$ gem fetch wxruby  
Downloaded wxruby-2.0.0-universal-darwin-9  
$ gem spec wxruby-2.0.0-universal-darwin-9.gem files | grep lib

- lib/wx  
[…]
- lib/wx.rb  
[…]

Nope.

Try:

require ‘wx’

instead.

Hey look! It’s even described right in the Getting Started tutorial:

[http://wxruby.rubyforge.org/wiki/wiki.pl?Getting\_Started](http://wxruby.rubyforge.org/wiki/wiki.pl?Getting_Started)

Which is linked off the homepage!

$ gem list -dr wxruby

\*\*\* REMOTE GEMS \*\*\*

wxruby (2.0.0, 1.9.7, 1.9.3, 1.9.2)  
Platforms:  
1.9.2: i686-darwin8.8.2, powerpc-darwin8.10.0  
1.9.3: universal-darwin  
1.9.7: i386-mswin32  
2.0.0: universal-darwin-9, x86-linux, x86-mingw32, x86-  
mswin32-60,  
x86\_64-linux  
Author: wxRuby development team  
Rubyforge: [http://rubyforge.org/projects/wxruby](http://rubyforge.org/projects/wxruby)  
Homepage: [http://wxruby.org/](http://wxruby.org/)

```
 Ruby interface to the wxWidgets GUI library

```

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [August 18, 2009, 9:15pm UTC](https://www.ruby-forum.com/t/gem-installation-oddity/173951/4 "2009-08-18T21:15:03Z")

</div>

On Aug 18, 2009, at 11:47, Pito S. wrote:

> Which, the way I was running it, led it to look at the ruby that comes  
> with OSX rather than the one I have designated as primary, which is  
> actually in /opt/local/…

Designate /opt/local/ruby as your primary ruby by setting your PATH,  
then /usr/bin/env can work as designed.

> My gem install is going into the primary ruby  
> install so when the sample app runs, it’s not finding it. So removing  
> that first line makes the thing work.

> $ gem which wxruby  
> Can’t find ruby library file or shared library wxruby  
> $

I told you that wxruby doesn’t exist already.

You can use gem contents -l as in my previous mail to see which files  
are in a gem to make a guess at what to use. Of course, you should go  
read the documentation first if you can’t immediately figure out how  
to use the gem.

> require ‘rubygems’  
> rescue LoadError  
> end  
> require ‘wx’

Why are you still trying to require a file that doesn’t exist (wxruby)  
and that the documentation says doesn’t exist (linked-to from my  
previous mail)? The documentation tells you which file to require.  
You even found a file that uses the wxruby gem and you’re still  
looking for the wrong file…

Not every gem name has a 1:1 mapping to the file you need to require.  
When require name\_of\_gem doesn’t work, you can use the various tools  
from my previous email to find the file you need to require. Of  
course the first spot you should check is the documentation for the  
gem you’re using.

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [August 18, 2009, 8:47pm UTC](https://www.ruby-forum.com/t/gem-installation-oddity/173951/5 "2009-08-18T20:47:57Z")

</div>

Eric H. wrote:  
I don’t think I exactly followed this. But in the meanwhile I think I  
have figured out what was tripping me up. The sample apps that come with  
wxruby begin with a line that looks like this:

#!/usr/bin/env ruby

# wxRuby2 Sample Code. Copyright © 2004-2008 wxRuby development team

# Freely reusable code: see SAMPLES-LICENSE.TXT for details

Which, the way I was running it, led it to look at the ruby that comes  
with OSX rather than the one I have designated as primary, which is  
actually in /opt/local/… My gem install is going into the primary ruby  
install so when the sample app runs, it’s not finding it. So removing  
that first line makes the thing work.

It still doesn’t explain to me why this is happening, but it might be,  
as the first response said, a bug in “gem which”. It’s a bit worrysome,  
but for the moment it’s not holding me up:

$ sudo gem install wxruby  
Successfully installed wxruby-2.0.0-universal-darwin-9  
1 gem installed  
Installing ri documentation for wxruby-2.0.0-universal-darwin-9…  
Installing RDoc documentation for wxruby-2.0.0-universal-darwin-9…  
$ gem which wxruby  
Can’t find ruby library file or shared library wxruby  
$

By the way, you asked:

> Is there even a wxruby in the gem?

The code doesn’t look for it; here’s what it looks like:

#!/usr/bin/env ruby

# wxRuby2 Sample Code. Copyright © 2004-2008 wxRuby development team

# Freely reusable code: see SAMPLES-LICENSE.TXT for details

begin  
require ‘rubygems’  
rescue LoadError  
end  
require ‘wx’

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [August 18, 2009, 9:39pm UTC](https://www.ruby-forum.com/t/gem-installation-oddity/173951/6 "2009-08-18T21:39:16Z")

</div>

Eric H. wrote:

> On Aug 18, 2009, at 11:47, Pito S. wrote:
> 
> > Which, the way I was running it, led it to look at the ruby that comes  
> > with OSX rather than the one I have designated as primary, which is  
> > actually in /opt/local/…
> 
> Designate /opt/local/ruby as your primary ruby by setting your PATH,  
> then /usr/bin/env can work as designed.

I think that’s how I have it:

$ echo $PATH  
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin  
~$ echo $GEMPATH  
/opt/local/lib/ruby/gems/1.8/  
~$

> > My gem install is going into the primary ruby  
> > install so when the sample app runs, it’s not finding it. So removing  
> > that first line makes the thing work.
> 
> > $ gem which wxruby  
> > Can’t find ruby library file or shared library wxruby  
> > $
> 
> I told you that wxruby doesn’t exist already.
> 
> You can use gem contents -l as in my previous mail to see which files  
> are in a gem to make a guess at what to use. Of course, you should go  
> read the documentation first if you can’t immediately figure out how  
> to use the gem.
> 
> > require ‘rubygems’  
> > rescue LoadError  
> > end  
> > require ‘wx’
> 
> Why are you still trying to require a file that doesn’t exist (wxruby)  
> and that the documentation says doesn’t exist (linked-to from my  
> previous mail)? The documentation tells you which file to require.  
> You even found a file that uses the wxruby gem and you’re still  
> looking for the wrong file…

Hm, I thought I was requiring wx.rb which in does exist. I agree that  
wxruby does not exist. Am I missing it totally?

However, your reply has helped me also uncover another misunderstanding,  
which may be what you were trying to say all along, that is that:

$gem which ‘xxx’  
looks for a file called xxx.rb in a gem, rather than a gem called xxx.  
That’s why my

$gem which wxruby

Keeps saying that it can’t find it, but now I tried

$gem which wx

and that succeeds.

> Not every gem name has a 1:1 mapping to the file you need to require.  
> When require name\_of\_gem doesn’t work, you can use the various tools  
> from my previous email to find the file you need to require. Of  
> course the first spot you should check is the documentation for the  
> gem you’re using.

Yeah, that’s a key bit of the puzzle that I hadn’t understood. Thanks!
