Why can't I load Nokogiri?

爷,独闯天下 提交于 2019-12-10 03:43:56

问题


I installed Nokogiri without any issues by running:

$ sudo gem install nokogiri
Building native extensions.  This could take a while...
Successfully installed nokogiri-1.5.9
1 gem installed
Installing ri documentation for nokogiri-1.5.9...
Installing RDoc documentation for nokogiri-1.5.9...

When I run nokogiri.rb:

#!/usr/bin/ruby -w

require 'nokogiri'

puts "Current directory is: #{ Dir.pwd }"
Dir.chdir("/home/askar/xml_files1") do |dirname|

  puts "Now in: #{ Dir.pwd }"
  xml_files = Dir.glob("ShipmentRequest*.xml")

  if xml_files.empty?
    puts "#{ dirname } is empty."
  else
    xml_files.each do |file|
      doc = Nokogiri::XML(open(file))
      # ... do something with the doc ...
    end
  end
end

I got the error:

$ ruby nokogiri.rb 
/home/askar/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- nokogiri (LoadError)
  from /home/askar/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

I'm using Ruby 1.9.3, but for some reason it refers to Ruby 1.9.1. Can this be the cause?


回答1:


If you observe closely, the path starts with /home/askar/.rvm/rubies/ruby-1.9.3-p429 so the load path should be correct.

Your problem is that you used sudo which will do a gem installation for the system ruby. Try again without sudo, just

gem install nokogiri

to install gems for the current rvm ruby.



来源:https://stackoverflow.com/questions/16850979/why-cant-i-load-nokogiri

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!