Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby gem install and "No such file to load"

I'm scripting with Ruby 1.9.2dev in Backtrack 5 but I'm having some problems when try to parse html entities with the library "htmlentities".

I cannot load the library although I have installed it with gem. I'll show you the problems I'm having in the console:

root@bt:~# gem list -d htmlentities

*** LOCAL GEMS ***

htmlentities (4.3.1)
    Author: Paul Battley
    Homepage: https://github.com/threedaymonk/htmlentities
    Installed at: /var/lib/gems/1.9.2

    A module for encoding and decoding (X)HTML entities.

root@bt:~# irb  irb(main):001:0> require 'htmlentities'  LoadError: no such file to load -- htmlentities    
       from (irb):1:in `require'    
       from (irb):1     
       from /usr/bin/irb:12:in `<main>'

This is the same problem I'm having with nokogiri. I installed the library with

gem install htmlentities

Do you have any idea why I'm having this problem?

Thank you.

EDITED:

I tried also with require 'rubygems' previously to any other require, but happens the same:

I tried require 'rubygems' but is happening the same:

irb(main):001:0> require 'rubygems'
=> false
irb(main):002:0> require 'htmlentities'
LoadError: no such file to load -- htmlentities
    from (irb):2:in `require'
    from (irb):2
    from /usr/bin/irb:12:in `<main>'
like image 650
Felipower Avatar asked Jan 19 '12 18:01

Felipower


2 Answers

Try to require 'rubygems' before the rest of your gems requirements.

rubygems is actually redefining the Kernel#require method to look for gems on your gempath. Whitout it ruby will just look for local/on path files.

like image 87
robertodecurnex Avatar answered Oct 02 '22 07:10

robertodecurnex


It took me a lot but now I know how to fix it. It's about GEM_PATH.

# echo "export GEM_PATH=/var/lib/gems/1.9.2/" >> ~/.bashrc 
# source ~/.bashrc

Now if I run irb:

# irb 
irb(main):003:0> require 'htmlentities'
=> true
irb(main):004:0>

WOOT!

like image 37
Felipower Avatar answered Oct 02 '22 07:10

Felipower