Godzilla74 Godzilla74 - 1 month ago 8
Ruby Question

LoadError on require

I have a simple ruby script that is using the

net-ping
gem which I have installed with
gem install net-ping
and have confirmation that it has installed:

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


In my script:
require '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)


In irb this all works fine, however when trying to run my script, it doesn't. Instead I get this error now:

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


This used to work fine on an older version of my script, however, I've since installed
Oh-My-Zsh
on my Mac, which I suspect is the issue.

So, I made sure my environment variables reference RVM (
printenv
):

rvm_prefix=/Users/golem
rvm_path=/Users/golem/.rvm
rvm_bin_path=/Users/golem/.rvm/bin


Is there something else that I'm missing that could be causing this?

Answer

So, net ping requires root privileges to run. So, if you are using sudo, the gem needs to be installed again. so, do sudo su first, run the gem install net-ping:1.7.8 again and try running your script.

That should work.

Comments