【问题标题】:LoadError on require需要加载错误
【发布时间】: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

还有其他我遗漏的东西可能导致这种情况吗?

【问题讨论】:

    标签: ruby macos rvm zsh


    【解决方案1】:

    因此,net ping 需要 root 权限才能运行。因此,如果您使用 sudo,则需要重新安装 gem。所以,首先执行sudo su,再次运行gem install net-ping:1.7.8,然后尝试运行您的脚本。

    应该可以的。

    【讨论】:

      猜你喜欢
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 2016-11-22
      • 2023-03-02
      • 2012-09-25
      • 1970-01-01
      • 2018-03-18
      • 2019-10-30
      相关资源
      最近更新 更多