2012-01-19 87 views
5

我在Ruby 1.9.2dev在Backtrack 5脚本编写,但当我尝试使用库“htmlentities”解析html实体时遇到了一些问题。红宝石安装和“没有这样的文件加载”

虽然我已经安装了宝石,但无法加载库。 我会告诉你我在控制台具有问题:

[email protected]:~# 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. 

[email protected]:~# 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>' 

这是我与引入nokogiri有同样的问题。我安装了库

gem install htmlentities 

你知道为什么我有这个问题吗?

谢谢。

编辑:

我试着也需要“RubyGems的”以前任何其他要求,但发生在相同的:

我试图要求“RubyGems的”,但正在发生的事情是一样的:

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

'require'rubygems''? –

回答

20

尝试到require 'rubygems'宝石的其他要求之前。

ruby​​gems实际上是重新定义了Kernel#require方法来寻找gempath上的宝石。 Whitout它红宝石只会寻找本地/路径文件。

3

它花了我很多,但现在我知道如何解决它。它关于GEM_PATH。

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

现在,如果我跑IRB:

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

WOOT!

+0

我已经下载了ruby版本管理器“rvm.io”,它自动修复了宝石路径,没有太大麻烦。这不是一个解决方案,而是一个很好的解决方法。 – Deano

相关问题