gpt4 book ai didi

rubygems - Ruby 找不到已安装的 gem

转载 作者:行者123 更新时间:2023-12-04 13:44:19 24 4
gpt4 key购买 nike

我在这里有点不知所措。我在 OSX10.6 上,我的 gem 都搞砸了。我正在尝试使用的 gem 之一是 Hashie。我在互联网上环顾四周,似乎有几个人遇到了类似的问题,但他们的解决方案似乎都不适用于我的情况。谢谢你看。

我所有的 ruby​​ 脚本/gems 都安装在/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>

一些环境变量:
gem 环境:
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/

$路径:
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

我很乐意张贴任何用于调试的命令的输出。

感谢您的关注!

最佳答案

正如 Adam Vandenberg 指出的那样,在加载 gem 之前,您需要 require "rubygems"
某些框架可能会为您加载它,您可以在 .irbrc 中将其设置为自动加载。如果你喜欢

关于rubygems - Ruby 找不到已安装的 gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4272805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com