ruby“require”是如何工作的



我使用的是Archlinux,ruby位置在/usr/bin/ruby-上

$ ruby --version 
ruby 2.0.0p247 (2013-06-27 revision 41674) [i686-linux]
$ gem install ffi
Building native extensions.  This could take a while...
Successfully installed ffi-1.9.0
Parsing documentation for ffi-1.9.0
Done installing documentation for ffi after 41 seconds
1 gem installed

我使用G-WAN执行ruby脚本,但当我使用require 'ffi'时,输出显示:

/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- ffi (LoadError)
    from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
    from /home/asd/bin/gwan_linux32-bit/127.0.0.1_8081/#127.0.0.1/csp/test.rb:1:in `<main>'

CCD_ 2显示:

/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- ffi_c (LoadError)
    from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
    from /home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi.rb:14:in `rescue in <top (required)>'
    from /home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi.rb:3:in `<top (required)>'
    from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
    from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
    from /home/asd/bin/gwan_linux32-bit/127.0.0.1_8081/#127.0.0.1/csp/test.rb:21:in `<main>'

p $LOAD_PATH的输出为:

["/usr/lib/ruby/site_ruby/2.0.0" # doesn't exists
, "/usr/lib/ruby/site_ruby/2.0.0/i686-linux" # doesn't exists
, "/usr/lib/ruby/site_ruby" # doesn't exists
, "/usr/lib/ruby/vendor_ruby/2.0.0" # doesn't exists
, "/usr/lib/ruby/vendor_ruby/2.0.0/i686-linux" # doesn't exists
, "/usr/lib/ruby/vendor_ruby" # doesn't exists
, "/usr/lib/ruby/2.0.0" 
, "/usr/lib/ruby/2.0.0/i686-linux"
]

外国金融机构的位置是:

$ locate ffi.rb
/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi.rb
/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi/ffi.rb
/opt/jruby/lib/ruby/shared/ffi.rb
/opt/jruby/lib/ruby/shared/ffi/ffi.rb
/opt/jruby/samples/ffi/ffi.rb

所以我尝试将目录添加到$LOAD_PATH

$LOAD_PATH.unshift '/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib'

现在CCD_ 4没有显示错误。。

如果我已经在~/.gem/ruby/2.0.0/gems 上安装了许多gem

$ ll ~/.gem/ruby/2.0.0/gems/ | wc
285    2558   17502

使用宝石的正确方法是什么?是通过将每个路径添加到$LOAD_path

这显然是一个Ruby配置问题,建议的RVM工具似乎解决了这个问题:

RVM是一个命令行工具,并使用从解释器到宝石。

正如"icktoofay"所建议的,G-WAN可以增加对RVM的支持,但我不确定这是否有意义,除非RVM变得比Ruby本身更主流(或被Ruby同化)。

现在,Jesly Varghese还告诉我们(如上),问题来自"您正在使用系统ruby,并在用户目录中调用gem"

您是否尝试在/opt/gwan下安装G-WAN?然后,这个PATH问题可能会消失。

相关内容

  • 没有找到相关文章

最新更新