Ruby gem install and “No such file to load”

2019-03-21 04:30发布

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>'

2条回答
做个烂人
2楼-- · 2019-03-21 05:01

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!

查看更多
唯我独甜
3楼-- · 2019-03-21 05:26

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.

查看更多
登录 后发表回答