我使用的ruby版本是1.8.6 我使用命令“gem install net-ssh”安装了gem“net / ssh” 但是在运行以下脚本
require 'rubygems'
require 'net/ssh'
HOST = '10.102.5.100'
USER = 'user'
PASS = 'test'
Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|
result = ssh.exec!('stat ssl')
puts result
end
错误:
/usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:106:in `load': undefined method `start_with?' for "*":String (NoMethodError)
from /usr/local/rubygems/lib/rubygems/custom_require.rb:36:in `partition'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:106:in `each'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:106:in `partition'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:106:in `load'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:81:in `foreach'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:81:in `load'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:63:in `for'
from /usr/local/rubygems/lib/rubygems/custom_require.rb:36:in `inject'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:62:in `each'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:62:in `inject'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh/config.rb:62:in `for'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh.rb:239:in `configuration_for'
from /usr/local/rubygems/gems/gems/net-ssh-2.9.1/lib/net/ssh.rb:182:in `start'
from TestSSH.rb:9
为什么我会收到此错误?
答案 0 :(得分:0)
正如您对问题的评论所指出的那样,问题出现了,因为Ruby 1.8.6没有String#start_with?
方法。最好的解决方案是升级到更新的Ruby。
也就是说,根据the net-ssh README,2.5.1之前的版本支持Ruby 1.8.x.从net-ssh版本2.5.0开始直观地检查文件lib / net / ssh / config.rb,确认它不使用start_with?
方法,因此您可以尝试使用该方法。请务必阅读the changelog以确保您使用的版本中包含所需的功能。