Gem在irb中找到,而不是在Ruby中

前端之家收集整理的这篇文章主要介绍了Gem在irb中找到,而不是在Ruby中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我安装了一些gem,我正在尝试在Ruby应用程序中使用它们:
require 'rubygems'
require 'mygem'

但是,当我运行应用程序时,我收到此错误:< internal:lib / ruby​​gems / custom_require>:29:inrequire’:没有要加载的文件 – mygem(LoadError)

但是,如果我尝试在irb中使用gem(确保首先要求’rubygems’),它可以正常工作.我应该做些什么?我试着谷歌搜索这个问题,但不明白.

在ruby,gem和irb上运行一个表明它们都在/ opt / local / bin /中,即

> which ruby
/opt/local/bin/ruby
> which gem
/opt/local/bin/gem
> which irb
/opt/local/bin/irb

更新回答提出的问题(是的,irb和ruby指向不同的文件夹):

$LOAD_PATH和$:in irb都包含似乎指向ruby 1.8文件夹:

/opt/local/lib/ruby/site_ruby/1.8
/opt/local/lib/ruby/site_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/site_ruby
/opt/local/lib/ruby/vendor_ruby/1.8
/opt/local/lib/ruby/vendor_ruby/1.8/i686-darwin10
/opt/local/lib/ruby/vendor_ruby
/opt/local/lib/ruby/1.8
/opt/local/lib/ruby/1.8/i686-darwin10
.

$:in ruby​​指向ruby 1.9.1文件夹:

/usr/local/lib/ruby/site_ruby/1.9.1
/usr/local/lib/ruby/site_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/vendor_ruby/1.9.1
/usr/local/lib/ruby/vendor_ruby/1.9.1/i386-darwin9.8.0
/usr/local/lib/ruby/vendor_ruby
/usr/local/lib/ruby/1.9.1
/usr/local/lib/ruby/1.9.1/i386-darwin9.8.0

gem env节目

RubyGems Environment:
  - RUBYGEMS VERSION: 1.4.1
  - RUBY VERSION: 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
  - INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /opt/local/bin/ruby
  - EXECUTABLE DIRECTORY: /opt/local/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-darwin-10
  - GEM PATHS:
     - /opt/local/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gempath" => ["/opt/local/lib/ruby/gems/1.8"]
     - :sources => ["http://rubygems.org/","http://gems.github.com","http://gems.github.com"]
  - REMOTE SOURCES:
     - http://rubygems.org/
     - http://gems.github.com
     - http://gems.github.com

irb中的Gem.path指向

/Users/grautur/.gem/ruby/1.8
/usr/local/lib/ruby/gems/1.8

红宝石中的Gem.path指向

/Users/grautur/.gem/ruby/1.9.1
/usr/local/lib/ruby/gems/1.9.1

解决方法

我不确定发生了什么事.但是,以下内容可能有所帮助.

在irb,做

require 'rubygems'
require 'mygem'
puts $:

然后,在红宝石中,做

require 'rubygems'
puts $:

如果你还没有解决问题,请告诉我们你得到了什么.

编辑:还打印出在命令行上执行gem env的结果.

编辑2:看看如果你在irb和ruby中都需要rubygems后输入Gem.path会发生什么.见thanks to Matt for describing Rubygems

原文链接:https://www.f2er.com/ruby/274213.html

猜你在找的Ruby相关文章