Gem Path Issue: RubyGems looking in the wrong place

12,597

Solution 1

Based on the path in your error message, your irb and apps are probably using the default system ruby.

What does which irb show? And what is the commandline you use to run your apps?

You may need to adjust the shebang line (the first line which starts with "#!") of your scripts to use /opt/local/bin/ruby.

Solution 2

Try adding this to your .bashrc?

export PATH=/opt/local/bin/gem:$PATH

That gives the your new gem path the first crack rather than the current, incorrect default.

Share:
12,597
Noah Clark
Author by

Noah Clark

I like you.

Updated on June 05, 2022

Comments

  • Noah Clark
    Noah Clark almost 2 years

    When I require certain gems, some of them work and some of them don't work. They seem to install find and I can do a gem list and they are there. However, when I try to run them in Irb or run my ruby programs from the terminal I get the following:

    LoadError: no such file to load -- sanitize
    
    /Library/Ruby/Site/1.8/rubygems/custom_require.rb:54:in `gem_original_require'
    

    And so I followed the guide on RubyGems and everything seems fine:

    noahclark$ gem list sanitize
    *** LOCAL GEMS ***
    sanitize (2.0.3)
    
    
    noahclark$ ruby -rubygems -e 'require "sanitize"'
    noahclark$ 
    
    noahclark$ which ruby
    /opt/local/bin/ruby
    noahclark$  gem env | grep 'RUBY EXECUTABLE'
    - RUBY EXECUTABLE: /opt/local/bin/ruby
    

    So then I tried:

    noahclark$ which gem
    /opt/local/bin/gem
    
    noahclark$ gem environment
    RubyGems Environment:
    - RUBYGEMS VERSION: 1.8.10
    - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10]
    - 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-10
     - GEM PATHS:
        - /opt/local/lib/ruby/gems/1.8
        - /Users/noahclark/.gem/ruby/1.8
     - GEM CONFIGURATION:
         - :update_sources => true
         - :verbose => true
        - :benchmark => false
        - :backtrace => false
        - :bulk_threshold => 1000
     - REMOTE SOURCES:
        - http://rubygems.org/
    

    You can see that which gem and gem environment are looking at two separate directories. I hunted around for a fix and I could only find something that suggested adding export PATH=$PATH:/opt/local/bin/gem to my .bashrc file. This did not fix it.

    How should I go about fixing this?

  • Noah Clark
    Noah Clark over 12 years
    which irb results in /opt/local/bin/irb
  • Kelvin
    Kelvin over 12 years
    @noahclark What error does this show (if any): irb -rubygems -r sanitize
  • Kelvin
    Kelvin over 12 years
    @noahclark How did you install ruby? If you used macports, it should've changed your ~/.profile so "/opt/local/bin" was first. You do have to exit any terminal session and open new ones - if you didn't, you might've installed some gems under the system ruby.
  • Noah Clark
    Noah Clark over 12 years
    Weird, I ran that it worked. I had restarted my computer to make sure that .bashrc was loaded, but that didn't help. Not sure what I did or why it works now but it does! Thanks!
  • Noah Clark
    Noah Clark over 12 years
    I just tried doing it and it was fixed before and it now flipped back so I'm having issues even though I haven't changed anything. Any ideas?
  • Kelvin
    Kelvin over 12 years
    @noah Do you mean irb -rubygems -r sanitize is failing? What's the error? Are you using a different terminal session than you did when it succeeded? Did you prepend /opt/local/bin (not /opt/local/bin/gem) to your PATH in .bashrc and restart the term session?
  • Kelvin
    Kelvin over 12 years
    @noah i should also ask, what does echo $PATH return in the terminal prompt?
  • Kelvin
    Kelvin over 12 years