ruby can't find installed gems, but irb can

John H's Avatar

John H

05 Jun, 2011 10:14 PM

I've installed some gems (via gem install thegem), but when I try requiring them in Ruby:

require 'rubygems'
require 'thegem'

I get a "no such file to load" error. When I try requiring them inside irb, though, they work fine.

I suspect the problem is something to do with my gem paths, since...

gem env shows

RubyGems Environment:
  - RUBY VERSION: 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
  - INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /opt/local/bin/ruby
  - EXECUTABLE DIRECTORY: /opt/local/bin
    - ruby
    - x86-darwin-10
     - /opt/local/lib/ruby/gems/1.8
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gempath" => ["/opt/local/lib/ruby/gems/1.8"]
     - :sources => ["", "", ""]

$: in irb show


and $: in ruby shows


(i.e., gem env and irb both point to 1.8 folders, but ruby points to a 1.9.1 folder), but I'm not sure how to point ruby to the right directories. Any suggestions?

  1. Support Staff 1 Posted by Eric Hodel on 06 Jun, 2011 08:47 PM

    Eric Hodel's Avatar

    You have two different ruby installs, so your PATH is misconfigured. gem and irb point to the /opt/local install while ruby points to the /usr/local install.

  2. 2 Posted by John H on 06 Jun, 2011 09:26 PM

    John H's Avatar

    Hmm, when I do a which gem/irb/ruby, though, all three point to binaries in /opt/local/bin (i.e., I get /opt/local/gem, /opt/local/irb, /opt/local/ruby).

    But assuming I'm still confused (very likely!) and that you're right in that ruby points to a different install, what would I need to do to fix my PATH?

  3. Support Staff 3 Posted by Eric Hodel on 06 Jun, 2011 09:48 PM

    Eric Hodel's Avatar

    What do the following say:

    ruby -rubygems -e 'p Gem.ruby'
    /opt/local/bin/ruby -rubygems -e 'p Gem.ruby'
    /usr/local/bin/ruby -rubygems -e 'p Gem.ruby'
  4. 4 Posted by John H on 06 Jun, 2011 09:55 PM

    John H's Avatar

    The first and last (ruby and /usr/local/bin/ruby) show /usr/local/bin/ruby. The middle shows /opt/local/bin/ruby.

  5. Support Staff 5 Posted by Eric Hodel on 06 Jun, 2011 11:04 PM

    Eric Hodel's Avatar

    You probably have an alias for ruby that points to /usr/local/bin/ruby, check alias

  6. 6 Posted by John H on 07 Jun, 2011 04:46 PM

    John H's Avatar

    Ah, yep, I had an alias for ruby (in order to point it to ruby 1.9 in /usr/local/bin/ruby). Does this mean I need to get gem to point to /usr/local/bin as well? How do I do that?

  7. Support Staff 7 Posted by Eric Hodel on 07 Jun, 2011 08:52 PM

    Eric Hodel's Avatar

    The best way is to stop using alias and change the order of $PATH instead. Place /usr/local/bin in front of /opt/local/bin

  8. 8 Posted by Sam Auciello on 21 Mar, 2012 05:28 PM

    Sam Auciello's Avatar

    I'm having the same issue on my MacBook Pro w/ OS 10.6 except that when I tried the commands from Post #4 above I got the following:

    $ ruby -rubygems -e 'p Gem.ruby'
    ruby: no such file to load -- ubygems (LoadError)
    $ /opt/local/bin/ruby -rubygems -e 'p Gem.ruby'
    /opt/local/bin/ruby: no such file to load -- ubygems (LoadError)
    $ /usr/local/bin/ruby -rubygems -e 'p Gem.ruby'

    What's the best way to make this work?

  9. Support Staff 9 Posted by Eric Hodel on 21 Mar, 2012 06:19 PM

    Eric Hodel's Avatar

    Sam, you can install rubygems with /opt/local/bin/ruby by following the manual install instructions at the bottom of

    Or you can remove /opt/local/bin/ruby.

    Check /opt/local/bin/ruby -v and /opt/local/bin/ruby -v. I would remove the older version (likely the one in /opt).

  10. 10 Posted by Sam Auciello on 21 Mar, 2012 06:46 PM

    Sam Auciello's Avatar

    Thanks Eric,

    that fixed it.

  11. Eric Hodel closed this discussion on 21 Mar, 2012 07:24 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac