Ruby脚本找不到所需的gem [英] Ruby script cannot locate required gem

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

问题描述

我正在尝试运行过去运行良好的Ruby脚本.我需要使用Mechanize gem,因此在脚本顶部,它显示为require 'mechanize'.但是,当我尝试立即运行脚本时,终端输出为:

I'm trying to run a Ruby script that has worked fine in the past. I need to use the Mechanize gem, so at the top of the script, it says require 'mechanize'. However, when I try to run the script now, the Terminal output reads:

/Users/codebiker/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mechanize (LoadError)
from /Users/codebiker/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from myscript.rb:2:in `<main>'

当我按照这里的建议运行gem env时,我得到:

When I run gem env, as suggested here, I get:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.2.1
  - RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin13.0]
  - INSTALLATION DIRECTORY: /Users/codebiker/.rvm/gems/ruby-2.1.0
  - RUBY EXECUTABLE: /Users/codebiker/.rvm/rubies/ruby-2.1.0/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/codebiker/.rvm/gems/ruby-2.1.0/bin
  - SPEC CACHE DIRECTORY: /Users/codebiker/.gem/specs
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-13
  - GEM PATHS:
     - /Users/codebiker/.rvm/gems/ruby-2.1.0
     - /Users/codebiker/.rvm/gems/ruby-2.1.0@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - :benchmark => false
     - :sources => ["http://rubygems.org/", "http://gemcutter.org"]
     - "install" => "--no-rdoc --no-ri"
     - "update" => "--no-rdoc --no-ri"
  - REMOTE SOURCES:
     - http://rubygems.org/
     - http://gemcutter.org
  - SHELL PATH:
     - /Users/codebiker/.rvm/gems/ruby-2.1.0/bin
     - /Users/codebiker/.rvm/gems/ruby-2.1.0@global/bin
     - /Users/codebiker/.rvm/rubies/ruby-2.1.0/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/local/bin
     - /opt/X11/bin
     - /usr/texbin
     - /Users/codebiker/.rvm/bin

运行rvm get head时,我得到:

Upgrading the RVM installation in /Users/codebiker/.rvm/
RVM PATH line found in /Users/codebiker/.bashrc /Users/codebiker/.zshrc.
RVM sourcing line found in /Users/codebiker/.bash_profile /Users/codebiker/.zprofile.
Upgrade of RVM in /Users/codebiker/.rvm/ is complete.

运行which ruby时,我得到:

/Users/codebiker/.rvm/rubies/ruby-2.1.0/bin/ruby

ruby -v给了我

ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]

任何建议,想法或技巧将不胜感激!我不知道这是怎么回事.

Any advice, thoughts, or tips would be appreciated! I have no idea what's wrong here.

推荐答案

必须先安装宝石,然后才能在脚本中require宝石.安装宝石;首先打开终端窗口,然后键入:

Gems must first be installed before you can require them in a script. To install a gem; first open a terminal window and then type:

gem install GEM-NAME或您的情况:gem install mechanize

这篇关于Ruby脚本找不到所需的gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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