Ruby gems无法在脚本中加载,但在irb中加载正常

时间:2010-12-23 09:30:11

标签: ruby rubygems development-environment environment irb

我无法通过保存的脚本加载任何宝石,但是在irb中一切似乎都运行良好:

$ irb
irb(main):001:0> require 'nokogiri'
=> true
irb(main):002:0> exit
$ cat test.rb
require 'rubygems'
require 'nokogiri'
require 'active_record'
$
$ ruby test.rb
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- nokogiri (LoadError)
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from test.rb:2
$
$ gem list --local

*** LOCAL GEMS ***

activemodel (3.0.3)
activerecord (3.0.3, 2.3.8)
activesupport (3.0.3, 2.3.8)
arel (2.0.6)
aws-s3 (0.6.2)
builder (2.1.2)
choice (0.1.4)
colored (1.2)
date-performance (0.4.8)
i18n (0.5.0)
mime-types (1.16)
nokogiri (1.4.3.1)
pg (0.9.0)
Platform (0.4.0)
trollop (1.16.2)
tzinfo (0.3.23)
utility_belt (1.1.0)
wirble (0.1.3)
xml-simple (1.0.12)
$
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [x86_64-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_64-linux
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/1.8
     - /root/.gem/ruby/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/
$
$ irb
irb(main):001:0> Gem.path
=> ["/root/.gem/ruby/1.8", "/usr/local/lib/ruby/gems/1.8"]

想法?

编辑:根据要求:

$ whereis ruby | xargs ls -l
ls: ruby:: No such file or directory
-rwxr-xr-x 1 root root    7762 Dec 21  2007 /usr/bin/ruby
-rwxr-xr-x 1 root root 2717160 Aug 17 19:34 /usr/local/bin/ruby
-rw-r--r-- 1 root root    3776 Dec 21  2007 /usr/share/man/man1/ruby.1.gz

/usr/lib/ruby:
total 24
drwxr-xr-x 30 root root 4096 Aug 17 19:21 1.8
drwxr-xr-x  3 root root 4096 Aug 12 23:04 gems
drwxr-xr-x  3 root root 4096 Dec 21  2007 site_ruby

/usr/local/lib/ruby:
total 32
drwxr-xr-x 28 root root 4096 Aug 17 19:34 1.8
drwxr-xr-x  3 root root 4096 Aug 17 19:40 gems
drwxr-xr-x  3 root root 4096 Aug 17 19:34 site_ruby
drwxr-xr-x  3 root root 4096 Aug 17 19:34 vendor_ruby
$
$ whereis irb | xargs ls -l
ls: irb:: No such file or directory
-rwxr-xr-x 1 root root 379 Aug 17 19:40 /usr/bin/irb
-rwxr-xr-x 1 root root 379 Aug 17 19:34 /usr/local/bin/irb

1 个答案:

答案 0 :(得分:0)

我刚刚安装了rvm,即使在我的默认ruby安装上,一切都突然正常工作。我猜这解决了。