1

我正在使用 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>'

require '/home/asd/.gem/ruby/2.0.0/gems/ffi-1.9.0/lib/ffi.rb'显示:

/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"
]

FFI 的位置是:

$ 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'

现在require 'ffi'显示没有错误..

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

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

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

4

1 回答 1

0

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

RVM 是一个命令行工具,可让您轻松安装、管理和使用从解释器到 gem 集的多个 ruby​​ 环境。

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

现在,Jesly Varghese 还告诉我们(上图),问题来自“您正在使用系统 ruby​​,并在用户目录中调用 gem”这一事实。

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

于 2013-07-24T06:51:37.230 回答