Ruby新手,遇到LOAD_PATH问题 [英] New to Ruby and am having trouble with LOAD_PATH

查看:109
本文介绍了Ruby新手,遇到LOAD_PATH问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近通过编译源代码在OS X 10.8.3上安装了Ruby 2.0.0。我检查了这个版本

I recently installed Ruby 2.0.0 on OS X 10.8.3 by compiling from source code. I checked the version with

$ ruby --version
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]

我检查了我的宝石版本

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.3
  - RUBY VERSION: 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-12
  - GEM PATHS:
     - /Library/Ruby/Gems/1.8
     - /Users/ehartsuyker/.gem/ruby/1.8
     - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :benchmark => false
     - :sources => ["http://rubygems.org/", "http://gemcutter.org"]
  - REMOTE SOURCES:
     - http://rubygems.org/
     - http://gemcutter.org

我注意到这里报告的Ruby版本与我安装的版本不匹配。我不知道这是否重要。

I noticed that the reported version of Ruby here does not match the version I installed. I don't know if this matters or not.

我有一段简单的代码叫做encrypy.rb,我正在运行。使用gem install rsa安装'rsa'gem后。

I have a simple piece of code called encrypy.rb that I'm running. After installing the 'rsa' gem with gem install rsa.

require 'rubygems'
require 'rsa'

key = RSA::KeyPair.generate(128)
ciphertext = key.encrypt("message")
puts(ciphertext)

当我运行它时,它会提示错误,说它找不到宝石。

When I run it, it gives an error saying it can't find the gem.

$ ruby encrypt.rb -Idirectory '/Library/Ruby/Gems/1.8'
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- rsa (LoadError)
    from /usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
    from encrypt.rb:2:in `<main>'

所以问题是,为什么Ruby没有找到gem似乎知道它在哪里?我该如何解决这个问题?

So the question is, why isn't Ruby finding the gem despite seeming to know where it is? And how can I fix it?

推荐答案

Ruby 1.8.7随OS X一起提供。看来 gem 看到的是这个版本,而不是你手动安装的2.0.0。正如其他人已经建议的那样,使用RVM或rbenv(哪一个取决于个人偏好)可以更轻松地处理不同的ruby环境。您可以在以下位置找到这些工具和说明:

Ruby 1.8.7 is shipped with OS X. It seems that gem is seeing that version instead of your manually installed 2.0.0. As others already suggested, using RVM or rbenv (which one depends on personal preference) makes handling different ruby environments much easier. You can find those tools and descriptions for them in the following places:

RVM: https://rvm.io/

rbenv: https://github.com/sstephenson/rbenv

这篇关于Ruby新手,遇到LOAD_PATH问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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