ruby can't find installed gems, but irb can
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:
- RUBYGEMS VERSION: 1.4.1
- 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
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/local/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gempath" => ["/opt/local/lib/ruby/gems/1.8"]
- :sources => ["http://rubygems.org/", "http://gems.github.com", "http://gems.github.com"]
- REMOTE SOURCES:
- http://rubygems.org/
- http://gems.github.com
- http://gems.github.com
$: in irb show
/opt/local/lib/ruby/site_ruby/1.8
/opt/local/lib/ruby/site_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/site_ruby
/opt/local/lib/ruby/vendor_ruby/1.8
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/vendor_ruby
/opt/local/lib/ruby/1.8
/opt/local/lib/ruby/1.8/i686-darwin10
and $: in ruby shows
/usr/local/lib/ruby/site_ruby/1.9.1
/usr/local/lib/ruby/site_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/vendor_ruby/1.9.1
/usr/local/lib/ruby/vendor_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/1.9.1
/usr/local/lib/ruby/1.9.1/i386-darwin9.8.0
(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?
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Eric Hodel on 06 Jun, 2011 08:47 PM
You have two different ruby installs, so your PATH is misconfigured.
gemandirbpoint to the /opt/local install whilerubypoints to the /usr/local install.3 Posted by John H on 06 Jun, 2011 09:26 PM
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
rubypoints to a different install, what would I need to do to fix my PATH?Support Staff 4 Posted by Eric Hodel on 06 Jun, 2011 09:48 PM
What do the following say:
5 Posted by John H on 06 Jun, 2011 09:55 PM
The first and last (
rubyand/usr/local/bin/ruby) show/usr/local/bin/ruby. The middle shows/opt/local/bin/ruby.Support Staff 6 Posted by Eric Hodel on 06 Jun, 2011 11:04 PM
You probably have an alias for ruby that points to /usr/local/bin/ruby, check
alias7 Posted by John H on 07 Jun, 2011 04:46 PM
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 getgemto point to/usr/local/binas well? How do I do that?Support Staff 8 Posted by Eric Hodel on 07 Jun, 2011 08:52 PM
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
9 Posted by Sam Auciello on 21 Mar, 2012 05:28 PM
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:
What's the best way to make this work?
Support Staff 10 Posted by Eric Hodel on 21 Mar, 2012 06:19 PM
Sam, you can install rubygems with /opt/local/bin/ruby by following the manual install instructions at the bottom of https://rubygems.org/pages/download
Or you can remove /opt/local/bin/ruby.
Check
/opt/local/bin/ruby -vand/opt/local/bin/ruby -v. I would remove the older version (likely the one in /opt).11 Posted by Sam Auciello on 21 Mar, 2012 06:46 PM
Thanks Eric,
that fixed it.
Eric Hodel closed this discussion on 21 Mar, 2012 07:24 PM.