红宝石列出,但不会加载(gem在用户目录中,而不是红宝石目录) [英] Ruby gem listed, but wont load (gem in user dir, not ruby dir)

查看:104
本文介绍了红宝石列出,但不会加载(gem在用户目录中,而不是红宝石目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得一些支持ruby和一些ruby宝石的web主机的宝石,但不是我需要使用的宝石中的一些。



按照说明,我在这里找到了 ,我将原始的宝石位置保留在我的gem路径,并将我自己的/ path / to / my / home / gems添加到〜/ .gemrc中

  gemhome:/ users / home / myuser / gems 
gempath:
- /usr/local/lib/ruby/gems/1.8
- / users / home / mysuser / gems

我手动下载了一些gem,并使用gem命令的--local和--install-dir选项进行安装。然后我做了一个gem list,并且实际上可以看到我安装在我的用户目录中的宝石,以及正常系统路径中的原始宝石。



如果我踢IRB或做红宝石-e,所有系统宝石都可以正常工作。然而,我无法得到我的用户目录安装宝石加载:

  $ ruby​​ -r ruby​​gems -erequire'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 / ruby​​gems / custom_require.rb:21:在'require'
从-e:1

我甚至尝试过老派的require_gem:

  $ irb -r ruby​​gems 
irb(主):001:0> require_gem'nokogiri'
Gem :: LoadError:无法从/usr/local/lib/ruby/site_ruby/1.8/rubygems.rb找到RubyGem nokogiri(> 0.0.0)

:204:在`report_activate_error'中
从/usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:141:in`activate'
从/ usr / local / lib / ruby​​ / site_ruby /1.8/rubygems.rb:37:in require_gem_with_options'$ b $ from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:31:in`require_gem'$ b $ from(irb): 1

从我的宝石列表中可以看到:

  nokogiri(1.3.3)
Nokogiri是一个HTML,XML,SAX和Reader解析器

我对所有用户目录安装宝石都有同样的问题。我在这里错过了什么?



编辑:这是不是的rails应用程序。这是一个命令行应用程序。编程:根据Rafe的建议,我查看了IRB的Gem.path。它仅 列出系统宝石路径,/usr/local/lib/ruby/gems/1.8,而不是我的用户目录路径。

解决方案

我遇到了同样的问题,我通过在ruby文件的顶部添加以下内容来修复它:

  require'rubygems'

希望有帮助


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.

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

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.

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

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

I have this same problem with all the user-directory install gems. What am I missing here?

EDIT: 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.

EDIT: 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.

解决方案

I had the same problem, I fixed it by adding the following at the top of the ruby file

require 'rubygems'

Hope that helps

这篇关于红宝石列出,但不会加载(gem在用户目录中,而不是红宝石目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆