Can't load Nokogiri gem when running a .rb file from a text editor, but it works fine in the Ruby command shell
-
30-06-2021 - |
Question
I use Scintilla Text Editor and Sublime Text 2.
Whenever I use them to run a Ruby script containing:
require 'nokogiri'
...I get this error:
C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- nokogiri (LoadError)
from C:/Program Files (x86)/ruby-1.9.2/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Users/MY_RUBY_SCRIPT.rb:3:in `<main>'
I'm using Ruby 1.9.3 and I made sure to require rubygems, but I still got the error.
However, when I run the script from the Command Prompt With Ruby, the script works fine.
Does anyone know why the script fails in text editors, but not in the Command Prompt?
Solution 2
Turns out I had both Ruby 1.9.2 and 1.9.3 installed, which caused the conflict in SciTE, which was trying to find the gem in Ruby 1.9.2 instead of 1.9.3. I uninstalled 1.9.2 and the script worked fine. If I do need 1.9.2 in the future, I suppose I'll have to learn RVM.
OTHER TIPS
Maybe your editor runs a different version of Ruby. You can check by running
puts RUBY_VERSION