我的智慧结束了。我在OSX10.6上,我的宝石都搞砸了。我试图使用的宝石之一是Hashie。我在互联网上环顾四周,有几个人似乎遇到了类似的问题,但我的解决方案似乎都不适用于我的情况。谢谢你的期待。
所有我的ruby脚本/宝石都安装在/opt/ruby-enterprise-1.8.7-2010.02中:
Komputor:~$ which ruby gem irb rails
/opt/ruby-enterprise-1.8.7-2010.02/bin/ruby
/opt/ruby-enterprise-1.8.7-2010.02/bin/gem
/opt/ruby-enterprise-1.8.7-2010.02/bin/irb
/opt/ruby-enterprise-1.8.7-2010.02/bin/rails
安装示例gem,hashie(和许多其他):
Komputor:~ $ gem list -l | wc -l
67
Komputor:~ $ gem list | grep hashie
hashie (0.4.0)
Komputor:gems $ cd /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems
Komputor:gems $ ls | grep hashie
drwxr-xr-x 13 root admin 442 Nov 24 17:13 hashie-0.4.0
然而,当我尝试从irb或脚本访问它们时,它都失败了:
Komputor:~ $ irb
irb(main):001:0> require 'hashie'
LoadError: no such file to load -- hashie
from (irb):1:in `require'
from (irb):1
irb(main):002:0>
一些环境变量: 宝石环境:
Komputor:gems $ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.0]
- INSTALLATION DIRECTORY: /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/ruby-enterprise-1.8.7-2010.02/bin/ruby
- EXECUTABLE DIRECTORY: /opt/ruby-enterprise-1.8.7-2010.02/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8
- /Users/<snip>/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
$ PATH:
Komputor:gems $ echo $PATH
/sw/bin:/sw/sbin:/opt/ruby-enterprise-1.8.7-2010.02/bin:/Applications/android-sdk-1.5/tools:/usr/brlcad/bin:/usr/local/mysql-5.0.67-osx10.5-x86_64/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/mongodb/bin:/sw/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/usr/X11R6/bin
我很乐意发布任何调试命令的输出。
感谢您的期待!
答案 0 :(得分:12)
正如Adam Vandenberg所指出的那样,在加载宝石之前,你需要require "rubygems"
某些框架可能会为您加载此内容,如果您愿意,可以在.irbrc
中将其设置为自动加载