8

I'm trying to get started with using Nokogiri. I ran the command

gem install nokogiri

as an administrator in Windows 7 (64-Bit). The console said "successfully installed" and "1 gem installed".

When I type in

gem list --local OR gem q --local

I see Nokogiri on the list of "Local Gems".

However, when I try to use it via the require statement (in NetBeans), I get an error that there is "no such file to load".

What am I doing wrong? I'm not a Ruby professional. This is also the first gem I've installed. Please dumb it down for me.

Tilo
  • 33,354
  • 5
  • 79
  • 106
Derek
  • 833
  • 2
  • 9
  • 13

4 Answers4

20

With Ruby 1.8, you have to require 'rubygems' before requiring any libraries installed as gems. With Ruby 1.9, that is not necessary anymore.

require 'rubygems'
require 'nokogiri'
...
Martin Vidner
  • 2,307
  • 16
  • 31
  • Thanks for the tip. I have tried using your suggestion, and it does not work. However, I do have Ruby 1.9 anyway. – Derek Mar 31 '11 at 06:33
  • Oh, I have figured out the problem! NetBeans was using JRuby 1.5 instead of 1.9. Thank you for pointing out versions, or I would not have checked this! – Derek Mar 31 '11 at 06:37
10

I realize this post is pretty old, but others may stumble here with the same problem, as I did. Novices like me may not realize that

require 'rubygems' 

must precede

require 'nokogiri'

At least, based on another URL post that gave me the idea, the addition of that line solved the problem for me with nokogiri.

Wayne
  • 59,728
  • 15
  • 131
  • 126
Sid
  • 101
  • 1
  • 2
4

Netbeans comes with built-in jRuby.

You can specify or check wich version of ruby currently used in your project in project's properties (higlighted section).

enter image description here

Viacheslav Molokov
  • 2,534
  • 21
  • 20
2

I was struggling with this one for a while, having upgraded to ruby 2.0.

The fix was to install nokigiri using apt-get

apt-get install ruby-nokogiri

As a side note dependencies can be seen using

$ gem dependency nokogiri

Gem nokogiri-1.6.1
  hoe (~> 3.7, development)
  hoe-bundler (>= 1.1, development)
  hoe-debugging (>= 1.0.3, development)
  hoe-gemspec (>= 1.0, development)
  hoe-git (>= 1.4, development)
  mini_portile (~> 0.5.0)
  minitest (~> 2.2.2, development)
  racc (>= 1.4.6, development)
  rake (>= 0.9, development)
  rake-compiler (~> 0.8.0, development)
  rdoc (~> 4.0, development)
  rexical (>= 1.0.5, development)
James McGuigan
  • 7,542
  • 4
  • 26
  • 29