Ruby gem install and “No such file to load”

耗尽温柔 提交于 2019-12-04 12:41:12

问题


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

回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/8931088/ruby-gem-install-and-no-such-file-to-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!