开发者

require rubygems works in irb but not in script

开发者 https://www.devze.com 2022-12-25 08:48 出处:网络
I have Ubuntu 9.04 Ruby 1.8 Rubygems 1.3.5 In irb, irb(main):002:0> require \'rubygems\' => true In a script

I have Ubuntu 9.04 Ruby 1.8 Rubygems 1.3.5

In irb,

irb(main):002:0> require 'rubygems'
=> true

In a script

$ ./test.rb 
./test.rb:2:in `require': no such file to load -- rubygems (LoadError)
from ./test.rb:2

$ gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  -开发者_运维技巧 RUBY VERSION: 1.8.6 (2009-08-04 patchlevel 383) [i686-linux]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://gems.rubyforge.org/


$ which ruby
/usr/local/bin/ruby

I think it may have something to do with my PATH, but I am not sure how or what to fix.

My $LOAD_PATH variable seems to have the path to the gem directories.

$ gem env gemdir
/usr/local/lib/ruby/gems/1.8
$ irb
irb(main):001:0> $LOAD_PATH
=> ["/usr/local/lib/ruby/site_ruby/1.8", "/usr/local/lib/ruby/site_ruby/1.8/i686-linux", "/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.8", "/usr/local/lib/ruby/1.8/i686-linux", "."]


Check the $LOAD_PATH, this variable contains the paths where ruby looks for when you use require.


I'm guessing that the shebang line in irb points to a different ruby than the one in your $PATH. Try

$ ruby $(type -p irb)

and see if your 'require "rubygems"' still works. If not, look at the #! line in irb to see what ruby it's using...

0

精彩评论

暂无评论...
验证码 换一张
取 消