【发布时间】:2015-11-24 16:45:48
【问题描述】:
我有一个简单的 ruby 脚本,它使用了 net-ping gem,我已经安装了 gem install net-ping 并确认它已安装:
Successfully installed net-ping-1.7.8
Parsing documentation for net-ping-1.7.8
Done installing documentation for net-ping after 0 seconds
1 gem installed
在我的脚本中: 需要'net/ping'
def can_ping(host)
@icmp = Net::Ping::ICMP.new(host)
if @icmp.ping
can_ping = true
else
can_ping = false
end
end
can_ping(www.google.com)
在 irb 中,这一切正常,但是在尝试运行我的脚本时,它没有。相反,我现在收到此错误:
/Users/golem/.rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- net/ping (LoadError)
from /Users/golem/.rvm/rubies/ruby-2.1.4/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from checkin.rb:2:in `<main>'
这曾经在我的旧版本脚本上运行良好,但是,我已经在我的 Mac 上安装了 Oh-My-Zsh,我怀疑这是问题所在。
所以,我确保我的环境变量引用了 RVM (printenv):
rvm_prefix=/Users/golem
rvm_path=/Users/golem/.rvm
rvm_bin_path=/Users/golem/.rvm/bin
还有其他我遗漏的东西可能导致这种情况吗?
【问题讨论】: