Ruby-on-rails 在 [] 中找不到 rails (>= 0) (Gem::LoadError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6278047/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:21:13  来源:igfitidea点击:

Could not find rails (>= 0) amongst [] (Gem::LoadError)

ruby-on-railsrubyruby-on-rails-3rubygemsrvm

提问by rigyt

After installing rvm, updating .gmrc file, updating rubygems and running gem install rails -v ">=3.1.0rc", I now seem to have a complete mess:

安装 rvm、更新 .gmrc 文件、更新 ruby​​gems 并运行后gem install rails -v ">=3.1.0rc",我现在似乎一团糟:

$ rails -v
/usr/local/lib/site_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find rails (>= 0) amongst [] (Gem::LoadError)
    from /usr/local/lib/site_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
    from /usr/local/lib/site_ruby/1.8/rubygems.rb:1182:in `gem'
    from /var/lib/gems/1.8/bin/rails:18


myhome@myhome-mini:~$ gem env

RubyGems Environment:
  - RUBYGEMS VERSION: 1.6.2
  - RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [i686-linux]
  - INSTALLATION DIRECTORY: /home/myhome/gems
  - RUBY EXECUTABLE: /home/myhome/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
  - EXECUTABLE DIRECTORY: /home/myhome/gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86-linux
  - GEM PATHS:
     - /home/myhome/gems
     - /usr/lib/ruby/gems/1.8
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gemhome" => "/home/myhome/gems"
     - "gempath" => ["/home/myhome/gems", "/usr/lib/ruby/gems/1.8"]
  - REMOTE SOURCES:
     - http://rubygems.org/

采纳答案by Ace Suares

I had to sudo gem install bundlerto make it work again.

我不得不sudo gem install bundler让它再次工作。

回答by pduersteler

I've had a similiar problem. Not sure if that helps you, but you might try to install gems with rvmsudo gem install [gemname]instead of just doing gem install [gemname]or sudo gem install [gemname].

我遇到了类似的问题。不确定这是否对您有帮助,但您可能会尝试安装 gemsrvmsudo gem install [gemname]而不仅仅是执行gem install [gemname]sudo gem install [gemname]

I try to explain this a bit because of the upvotes:
This basically is a path issue. If you set up gems via gem install, they mostly likely will be in another directory (e.g. /usr/local/) compared to gems set up via bundler (where you can override it with --path). Using sudomay also set them up into another directory since sudostarts a subshell which has a different environment then. This is why you have rvmsudo.

由于赞成票,我尝试解释一下:
这基本上是一个路径问题。如果您通过 设置 gem gem install/usr/local/与通过 bundler 设置的 gem 相比(您可以使用 覆盖它--path),它们很可能位于另一个目录中(例如)。使用sudo也可以将它们设置到另一个目录中,因为sudo启动了一个具有不同环境的子shell。这就是为什么你有rvmsudo.

If you want to see the differences, compare $PATH, $GEM_HOME, $GEM_PATHand $BUNDLE_PATHwhen echoing directly, with sudoand with rvmsudo.

如果你想看到的差异,比较$PATH$GEM_HOME$GEM_PATH$BUNDLE_PATH直接呼应的时候,用sudo并用rvmsudo

回答by Huy Thai

I got a problem similar to this, there may be a compatible problem of rvm. I fixed by updating rvm to latest version:

我遇到了类似的问题,可能是rvm的兼容问题。我通过将 rvm 更新到最新版本来修复:

curl -L https://get.rvm.io | bash -s stable --ruby

Then you should reload rvm or just open new terminal window. Then I reinstalled the bundler 'gem install bundler' and ran 'bundle install' as normal

然后你应该重新加载 rvm 或者只是打开新的终端窗口。然后我重新安装了捆绑器“gem install bundler”并照常运行“bundle install”

回答by Sv1

rvm rubygems current

did the trick for me.

帮我解决了这个问题。

回答by naiteluo

remove ruby first then

先删除红宝石然后

sudo apt-get install build-essential libssl-dev libreadline5 libreadline5-dev zlib1g zlib1g-dev

to install all needed lib then you could install ruby and rails

安装所有需要的库然后你可以安装 ruby​​ 和 rails

rvm install 1.9.3
rvm --default use 1.9.3
rvm gem install rails

回答by Derek Strickland

I had pretty much the same message when trying to generate a controller after installing IntelliJ IDEA and the associated Plugin for Rail Dev. From my app directory I just executed bundle install and was then able to generate controllers again.

在安装 IntelliJ IDEA 和相关的 Rail Dev 插件后尝试生成控制器时,我收到了几乎相同的消息。从我的应用程序目录中,我刚刚执行了 bundle install ,然后能够再次生成控制器。

回答by doz87

I know this is a really old question but I just recently decided to move to RVM on a server I had setup a while ago and was having this same problem where gems were being installed in the wrong place and it was just messing everything up.

我知道这是一个非常古老的问题,但我最近才决定在我不久前设置的服务器上转移到 RVM,并且遇到了同样的问题,其中 gem 安装在错误的位置,它只是把一切都搞砸了。

After a few hours of crawling through SO, I finally figured out that in my .gemrcfile in my root folder, I had previously setup the gemhome: and gempath:variables and they were messing with the whole system.

经过几个小时的爬行之后,我终于发现在.gemrc我的根文件夹中的文件中,我之前设置了gemhome: and gempath:变量并且它们正在搞乱整个系统。

After removing these lines, all my gems were working property.

删除这些线后,我所有的宝石都是有效的。

Just thought I would post my answer in case someone was in the same position.

只是想我会发布我的答案,以防有人处于相同的位置。