Ruby-on-rails 找不到 gem rails - Gem::GemNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9686052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
can't find gem rails - Gem::GemNotFoundException
提问by zachar
Using ubuntu 10.04, rvm. At first, I've installed ruby 1.9.2 with rvm, gem rails and generated some new project and started it successfully. Everything was working fine. But after changing to another project, executing bundle install command (output looks OK) and starting rails server - error occurs:
使用 ubuntu 10.04,rvm。起初,我已经安装了 ruby 1.9.2 和 rvm,gem rails 并生成了一些新项目并成功启动了它。一切正常。但是在更改到另一个项目后,执行 bundle install 命令(输出看起来不错)并启动 rails server - 发生错误:
rails s
导轨
/home/jacek/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/site_ruby/1.9.1/rubygems.rb:316:in `bin_path': can't find gem rails ([">= 0"]) with executable rails (Gem::GemNotFoundException)
from /home/jacek/.rvm/gems/ruby-1.9.2-p318/bin/rails:19:in `<main>'
gem list rails
宝石列表导轨
*** LOCAL GEMS ***
rails (3.2.2)
gem env
宝石环境
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.18
- RUBY VERSION: 1.9.2 (2012-02-14 patchlevel 318) [i686-linux]
- INSTALLATION DIRECTORY: /home/jacek/.rvm/gems/ruby-1.9.2-p318
- RUBY EXECUTABLE: /home/jacek/.rvm/rubies/ruby-1.9.2-p318/bin/ruby
- EXECUTABLE DIRECTORY: /home/jacek/.rvm/gems/ruby-1.9.2-p318/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/jacek/.rvm/gems/ruby-1.9.2-p318
- /home/jacek/.rvm/gems/ruby-1.9.2-p318@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
My Path (includes EXECUTABLE DIRECTORY: /home/jacek/.rvm/gems/ruby-1.9.2-p318/bin )
我的路径(包括可执行目录: /home/jacek/.rvm/gems/ruby-1.9.2-p318/bin )
/home/jacek/.rvm/gems/ruby-1.9.2-p318/bin:/home/jacek/.rvm/gems/ruby-1.9.2-p318@global/bin:/home/jacek/.rvm/rubies/ruby-1.9.2-p318/bin:/home/jacek/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
I would be grateful for any help
我将不胜感激任何帮助
采纳答案by Batkins
If you use the command bundle installto install your gems off of a GEMFILE, it will install the gems into your default system location for gems, as outlined in the bundler docs here. After that, you can use bundlers bundle execcommand to execute a command in the context of the bundle, as outlined in the docs here. This will ensure that the version of the gem you installed using bundle installis executed.
如果您使用该命令bundle install从 a 安装您的 gems GEMFILE,它会将这些 gems 安装到您的 gems 的默认系统位置,如bundler docs here 中所述。之后,您可以使用 bundlersbundle exec命令在包的上下文中执行命令,如此处的文档中所述。这将确保您安装的 gem 版本bundle install被执行。
If you look at the homepage for bundler, which provides an overview of the docs, it states the following:
如果你查看bundler的主页,它提供了文档的概述,它说明了以下内容:
In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle.
However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.
在某些情况下,如果可执行文件恰好安装在您的系统中并且没有引入任何与您的包冲突的 gem,那么在没有 bundle exec 的情况下运行可执行文件可能会起作用。
然而,这是不可靠的,并且是相当大的痛苦的根源。即使它看起来有效,但将来或在另一台机器上可能无法使用。
I'm guessing that you run gem which railsin your console, and then run bundle show railsin your console, the default installed rails installation for your system differs from the one installed for your bundle.
我猜您gem which rails在控制台中运行,然后bundle show rails在控制台中运行,系统的默认安装 rails 安装与您的包安装的不同。
You say that you are using rvmfor your rubyand gemmanagement. I'm thinking you may not have properly configured it. Trying executing the rvm notescommand in your console to ensure that you have addressed all of the required/recommended steps for installation on your OS. You want to ensure that the executables for rvmare the first things included in your path when you run echo $PATHideally. This will ensure that the gems installed for rvmwill be the ones executed when you try executing them without prefixing bundle exec. If rvm notesdoesn't give you the hints necessary to accomplish that, then try carefully reviewing the docs for installation on the RVM website.
你说你是rvm为你ruby和gem管理使用。我想你可能没有正确配置它。尝试rvm notes在您的控制台中执行该命令,以确保您已完成在您的操作系统上安装所需/推荐的所有步骤。rvm当您echo $PATH理想地运行时,您希望确保其可执行文件是路径中首先包含的内容。这将确保安装的 gemsrvm将是您尝试在没有前缀的情况下执行它们时执行的 gems bundle exec。如果rvm notes没有为您提供完成该操作所需的提示,请尝试仔细查看RVM 网站上的安装文档。
回答by Gonzalo Aguilar Delgado
For me just installed bundler. This makes everything work again.
对我来说刚刚安装了捆绑器。这使一切重新工作。
gem install bundler --no-ri --no-rdoc
回答by rust
You can switch version between Ruby with $ rvm use --default 2.4.0for example
您可以使用Ruby之间进行切换的版本 $ rvm use --default 2.4.0,例如
But for your problem try this :
但是对于您的问题,请尝试以下操作:
$ gem install bundler$ gem install rails
$ gem install bundler$ gem install rails
Hope it helps !
希望能帮助到你 !
回答by Jagdish Narayandasani
I think below command will work
我认为下面的命令会起作用
gem pristine rails

