列出了Ruby gem,但无法加载(用户目录中的宝石,而不是ruby目录中的宝石) [英] Ruby gem listed, but won't load (gem in user dir, not ruby dir)
问题描述
我正在尝试在支持ruby的Web主机上运行一些宝石以及一些ruby宝石,但是我不需要使用其中的一些宝石.
I'm trying to get some gems working on a web-host which supports ruby and some ruby gems, but not some of the ones I need to use.
按照我在此处中找到的说明进行操作,我保留了原始的gem位置在我的gem路径中,然后在/path/to/my/home/gems中将我自己的添加到〜/.gemrc
Following the instructions I found here, I kept the original gem location in my gem path, and added my own at /path/to/my/home/gems to ~/.gemrc
gemhome: /users/home/myuser/gems
gempath:
- /usr/local/lib/ruby/gems/1.8
- /users/home/mysuser/gems
我手动下载了一些gems,并使用gem命令的--local和--install-dir选项进行了安装.然后,我做了一个宝石列表",实际上可以看到我安装在用户目录中的宝石,以及正常系统路径中的原始宝石.
I downloaded some gems manually and did installs using the --local and --install-dir options of the gem command. I then did a "gem list", and can in fact see the gems I installed in my user directory, as well as the original gems in the normal system path.
如果我踩IRB或使用ruby -e,则所有系统宝石都可以正常工作.但是,我无法加载已安装gem的用户目录:
If I kick on IRB or do a ruby -e, all the system gems work fine. However, I can't get my user directory installed gems loaded:
$ ruby -r rubygems -e "require 'nokogiri'"
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__': no such file to load -- nokogiri (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
from -e:1
我什至尝试过旧学校require_gem:
I even tried the old school require_gem:
$ irb -r rubygems
irb(main):001:0> require_gem 'nokogiri'
Gem::LoadError: Could not find RubyGem nokogiri (> 0.0.0)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:204:in `report_activate_error'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:141:in `activate'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:37:in `require_gem_with_options'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:31:in `require_gem'
from (irb):1
从我的宝石列表"中,我可以看到:
From my "gems list" I can see:
nokogiri (1.3.3)
Nokogiri is an HTML, XML, SAX, and Reader parser
所有用户目录安装gem都存在相同的问题.我在这里想念什么?
I have this same problem with all the user-directory install gems. What am I missing here?
这不是 一个Rails应用.这是针对命令行应用程序的.该程序将由我的用户帐户执行,就像上面显示的测试一样.
This is not a rails app. This is for a command line-application. The program will be executed by my user account, just like the tests shown above in.
根据Rafe的建议,我查看了IRB的Gem.path.它仅 列出系统gem路径/usr/local/lib/ruby/gems/1.8,而不列出我的用户目录路径.
Per Rafe's suggestion, I looked at Gem.path from IRB. It only lists the system gem path, /usr/local/lib/ruby/gems/1.8, and not my user dir path as well.
推荐答案
我遇到了同样的问题,我通过在ruby文件顶部添加以下内容解决了该问题
I had the same problem, I fixed it by adding the following at the top of the ruby file
require 'rubygems'
希望有帮助
这篇关于列出了Ruby gem,但无法加载(用户目录中的宝石,而不是ruby目录中的宝石)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!