Ruby脚本找不到所需的gem
我正在尝试运行一个Ruby脚本,它在过去工作得很好。我需要使用Mechanize gem,因此在脚本顶部,它说Ruby脚本找不到所需的gem,ruby,rubygems,rvm,bundler,gemfile,mechanize,rails,gemfile.lock,Ruby,Rubygems,Rvm,Bundler,Gemfile,Mechanize,Rails,Gemfile.lock,我正在尝试运行一个Ruby脚本,它在过去工作得很好。我需要使用Mechanize gem,因此在脚本顶部,它说需要“Mechanize”。但是,当我现在尝试运行脚本时,终端输出显示: /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 (Load
需要“Mechanize”
。但是,当我现在尝试运行脚本时,终端输出显示:
/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>'
当我运行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.
当我运行哪个ruby
时,我得到:
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.
/Users/codebiker/.rvm/rubies/ruby-2.1.0/bin/ruby
ruby-v给了我:
ruby 2.1.0p0(2013-12-25修订版44422)[x86_64-darwin13.0]
任何建议、想法或提示都将不胜感激!我不知道这里出了什么问题 Gems必须先安装,然后才能
在脚本中要求它们。安装宝石;首先打开终端窗口,然后键入:
gem-install gem-NAME
或者在您的情况下:gem-install-mechanize
如果使用,请添加到您的gem链接中:
然后为您的或其他项目文件夹发布捆绑包安装:
$ bundle install
确保捆绑包安装后,gem存在于中
即使您不使用bundler,也要确保bundle找到gem:
$ bundle show mechanize
/path/to/mechanize/gem
然后,如果你的应用程序不是应用程序,只需使用以下工具运行你的应用程序:
$ bundle exec ./your_app
可能太明显了,gem安装对了吗?键入这是cmdgem安装mechanize
这完全修复了它-谢谢!然而,我不确定为什么Mechanize不再存在了。我已经在我的计算机上的脚本中多次使用Mechanize gem,所以我只是认为没有必要再次安装它。为什么它会突然消失?这可能与我最近安装的Ruby 2.1有关吗?是的,这完全正确。每个ruby安装都有一个独立的gems目录。很高兴我能帮忙。快乐编码!反应很好,谢谢!我投票认为feed_me_code的答案是正确的,因为这只是一个脚本,不是一个完整的应用程序,但我很感谢你的建议。我很好奇你是否碰巧知道宝石为什么消失了。(我永远不会卸载它,因为我经常使用它。)@CodeBiker如果你使用rvm,你可以将它安装到其他gemset中。或者,如果您使用了root安装,也可以将其视为其他gemset。
$ bundle exec ./your_app