What to do when Net-SSH complains about exec! method missing? - ruby

This is driving me crazy. I run into this every now and then on a new ubuntu/debian server.
Basically I can't do a exec! through net-ssh. Note, that I can require 'net/ssh' perfectly fine.
sample code
require 'rubygems'
require 'net/ssh'
Net::SSH.start('my.random.box', 'myuser', :forward_agent => "true") do |ssh|
#output = ssh.exec("hostname")
#puts output
output = ssh.exec!("hostname")
puts stdout
end
relevant system environment info
me#box:~$ gem list | grep net-ssh
net-ssh (2.0.11)
me#box:~$ which ruby
/usr/bin/ruby
me#box:~$ which gem
/usr/bin/gem
cyn0n#spicetrader:~$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.4
- RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/me/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com

A couple of things to try:
Verify that the exec! method is in the source.
Check both gem repositories to make sure there isn't an older net-ssh version in there. gem list has some oddities; it's more straightforward to just go into the directories and see what's there.
require the current version in your script.
require 'rubygems'
gem 'net-ssh', '=2.0.11'
require 'net-ssh'

Related

How to set correct Ruby version in gem environment

Note: This question relates to How can I get bundler to use the Ruby version set by chruby and .ruby-version?.
Using chruby I have Ruby 1.8.7 installed on macOS:
$ ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin17.4.0]
Also, I have used gem update --system 1.8.30 to install a specific version of RubyGems which I am hoping is compatible. This would appear to be installed properly:
$ gem --version
1.8.30
However, my RubyGems environment shows the incorrect version of Ruby (2.5.0):
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.30
- RUBY VERSION: 2.5.0 (2017-12-25 patchlevel 0) [x86_64-darwin17]
- INSTALLATION DIRECTORY: /Users/keithpitty/.gem/ruby/1.8.7
- RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
- EXECUTABLE DIRECTORY: /Users/keithpitty/.gem/ruby/1.8.7/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-17
- GEM PATHS:
- /Users/keithpitty/.gem/ruby/1.8.7
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
How can I fix the RubyGems environment to use the version of Ruby that chruby has set?
My missing step was installing RubyGems 1.6.2 from source. Following advice elsewhere from Dan Cheail, I did the following:
curl -O https://rubygems.org/rubygems/rubygems-1.6.2.tgz
(and then unzipped it)
cd rubygems-1.6.2
chruby ruby-1.8.7-p374
ruby setup.rb
gem update --system 1.8.25
And then my RubyGems environment was fixed:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.25
- RUBY VERSION: 1.8.7 (2013-06-27 patchlevel 374) [i686-darwin17.4.0]
- INSTALLATION DIRECTORY: /Users/keithpitty/.gem/ruby/1.8.7
- RUBY EXECUTABLE: /Users/keithpitty/.rubies/ruby-1.8.7-p374/bin/ruby
- EXECUTABLE DIRECTORY: /Users/keithpitty/.gem/ruby/1.8.7/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-17
- GEM PATHS:
- /Users/keithpitty/.gem/ruby/1.8.7
- /Users/keithpitty/.rubies/ruby-1.8.7-p374/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/

`require': no such file to load -- socket (LoadError)

I wrote a homework assignment on my Mac at home and am now trying to run it on the Linux machines at school (where it will be graded) and am getting:
.rb:1:in `require': no such file to load -- socket (LoadError)
Obviously I am trying to use Ruby's socket class:
require 'socket'
Checking the schools ruby version I see: ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-linux]
Shouldn't this version of the sockets? Am I doing something wrong? Anyway to get this to work?
gem env output:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/devans/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/

`require`ing user-installed Ruby module

I've successfully installed my ruby gem to a subdirectory of ~ using the --user-install option to gem. I can now see it under ~/.gem/ruby/1.8/gems/.
However, I'm unable to require it from my script:
./public_html/tt_web/index.cgi:2:in `require': no such file to load -- mbox (LoadError)
from ./public_html/tt_web/index.cgi:2
I added ~/.gem/ruby/1.8/bin to my PATH variable per the information here (and I've verified it actually worked with echo $PATH).
What else do I need to load gems from a custom path?
Here is the output of gem env, if it helps:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/1.8
- /home/elliott/.gem
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gempath" => ["/home/elliott/.gem", "/var/lib/gems/1.8"]
- "install" => "--user-install"
- REMOTE SOURCES:
- http://rubygems.org/
Well, I have no idea why this works, but adding require 'rubygems' to the top of my code fixed everything. Perhaps someone else could still shine some light on why, but I'm just happy it's working now :)

`gem_original_require': no such file to load -- midiator

I have this error loading a ruby file:
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- midiator (LoadError)
RubyGems Environment:
RUBYGEMS VERSION: 1.3.6
RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.7.0]
INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
RUBY EXECUTABLE: /usr/local/bin/ruby
EXECUTABLE DIRECTORY: /usr/local/bin
RUBYGEMS PLATFORMS:
ruby
x86-darwin-9
GEM PATHS:
/usr/local/lib/ruby/gems/1.8
/Users/pableras/.gem/ruby/1.8
GEM CONFIGURATION:
:update_sources => true
:verbose => true
:benchmark => false
:backtrace => false
:bulk_threshold => 1000
I had a lot of problems tu install rubygems and now I have problems again with midiator gem. I think something is not well configured. It is like the paths are not properly configured (Midiator gem is installed), but I do not know how to fix this.
Turning this into an answer as it solved the problem:
Is it listed when you do gem list?

rubygems update broke ruby on OSX

I was having some trouble running some Ruby scripts. While trying to get these scripts to run I tried lots of different things as well as updating rubygems as I thought this may be the problem. Since then I can't get any Ruby scripts to run.
I think that if I can revert rubygems back to it's original version I may be able to run Ruby scripts again, but I don't know how.
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/ryan/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org/
$ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
$ which -a ruby
/opt/local/bin/ruby
/opt/local/bin/ruby
/usr/bin/ruby
/usr/local/bin/ruby
$ which -a gem
/usr/bin/gem
/usr/local/bin/gem
Thank you for any help in advance.
Ryan
$ ruby spidr_start_at.rb
spidr_start_at.rb:1:in `require': no such file to load -- rubygems (LoadError)
from spidr_start_at.rb:1
$ cat spidr_start_at.rb
require 'rubygems'
require 'uri'
require 'spidr'
url = 'http://www.ethicalhack3r.co.uk'
puts "Spidr.start_at()"
puts
Spidr.start_at(url, :depth => 1) do |spider|
spider.every_page do |page|
puts page.url.to_s
end
end
It seems that you have multiple versions of ruby(and gem) installed. It is advised to use rvm when maintaining multiple ruby versions. Or clean up your wrong/old/unneeded installations.
For downgrading Rubygems, you can do the following:
sudo gem update --system VERSION
You obviously have to put a real version there.

Resources