0

Ruby 1.9.3 Very simple code and very simple question I can't deal with:

gem list --local
nokogiri (1.5.5)

gem q --local
nokogiri (1.5.5)

But a ruby script (not Rails):

require 'nokogiri'
doc = Nokogiri.XML("some valid xml....")

gives me

/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- nokogiri (LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/alex/test.rb:3:in `<main>'
[Finished in 0.1s with exit code 1]

I'm aware that it's not necessary to use require 'rubygems', but even when I do that, it does not work either.

gem environment
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.24
  - RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/alex/.rvm/gems/ruby-1.9.3-p194
  - RUBY EXECUTABLE: /home/alex/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
  - EXECUTABLE DIRECTORY: /home/alex/.rvm/gems/ruby-1.9.3-p194/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/alex/.rvm/gems/ruby-1.9.3-p194
     - /home/alex/.rvm/gems/ruby-1.9.3-p194@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - http://rubygems.org/


gem which nokogiri
/home/alex/.rvm/gems/ruby-1.9.3-p194/gems/nokogiri-1.5.5/lib/nokogiri.rb
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205
  • What OS are you using, and how are you running ruby (e.g. rbenv?). I'm running `ruby 1.9.3p194 (2012-04-20 revision 35410)` on OS X and the above works perfectly. – djlumley Oct 31 '12 at 11:17
  • That's ubuntu 12. I'm running that in Sublime text2. Other ruby scripts work perfectly, thus this issue is not because of Sublime Text. – Alan Coromano Oct 31 '12 at 11:21
  • Would you mind adding the output of `gem environment`? – djlumley Oct 31 '12 at 11:29
  • What do you mean when you say you are running this from Sublime Text? – tdgs Oct 31 '12 at 11:34
  • I mean that I'm running that from Sublime Text. Exactly. – Alan Coromano Oct 31 '12 at 11:36
  • if you're using rvm, are you sure you are installing that gem in the right gemset? If yes, are you running your script in that gemset? – Castilho Oct 31 '12 at 11:42
  • I use rvm. I don't know if I installed nokogiri correctly or not. I just installed it like I always do: gem install nokogiri. How do I check that? – Alan Coromano Oct 31 '12 at 11:46

2 Answers2

3

It happens because of the wrong Sublime Text build system. The right one is here How to run ruby files in sublime-text-2

Community
  • 1
  • 1
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205
-2

you need to add Nokogiri to the Gemfile (with the line gem 'nokogiri').

vijikumar
  • 1,805
  • 12
  • 16