Rails Ruby gem版本问题

时间:2017-03-09 15:30:49

标签: ruby-on-rails ruby

我使用不同项目的Ruby版本做了一些事情,现在当我想要启动某个项目时,我有以下Gem错误:

/home/glory/.rbenv/versions/2.2.4/lib/ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'railties' (>= 0) among 14 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/home/glory/.rvm/gems/ruby-2.2.4:/home/glory/.rvm/gems/ruby-2.2.4@global', execute `gem env` for more information
    from /home/glory/.rbenv/versions/2.2.4/lib/ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
    from /home/glory/.rbenv/versions/2.2.4/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
    from /home/glory/.rbenv/versions/2.2.4/bin/rails:22:in `<main>'

当我输入gem env时,我得到:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.6.10
  - RUBY VERSION: 2.2.4 (2015-12-16 patchlevel 230) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/glory/.rvm/gems/ruby-2.2.4
  - USER INSTALLATION DIRECTORY: /home/glory/.gem/ruby/2.2.0
  - RUBY EXECUTABLE: /home/glory/.rvm/rubies/ruby-2.2.4/bin/ruby
  - EXECUTABLE DIRECTORY: /home/glory/.rvm/gems/ruby-2.2.4/bin
  - SPEC CACHE DIRECTORY: /home/glory/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /home/glory/.rvm/rubies/ruby-2.2.4/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/glory/.rvm/gems/ruby-2.2.4
     - /home/glory/.rvm/gems/ruby-2.2.4@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/glory/.rvm/gems/ruby-2.2.4/bin
     - /home/glory/.rvm/gems/ruby-2.2.4@global/bin
     - /home/glory/.rvm/rubies/ruby-2.2.4/bin
     - /home/glory/.rvm/bin
     - /usr/local/heroku/bin
     - /home/glory/.rbenv/plugins/ruby-build/bin
     - /home/glory/.rbenv/shims
     - /home/glory/.rbenv/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /usr/games
     - /usr/local/games

我该如何解决?

2 个答案:

答案 0 :(得分:1)

仔细查看错误日志的开头:

/home/glory/.rbenv/versions/2.2.4/lib/ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'railties' (>= 0) among 14 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/home/glory/.rvm/gems/ruby-2.2.4:/home/glory/.rvm/gems/ruby-2.2.4@global', execute `gem env` for more information

并在PATH信息中:

 - /home/glory/.rvm/gems/ruby-2.2.4/bin
 - /home/glory/.rvm/gems/ruby-2.2.4@global/bin
 - /home/glory/.rvm/rubies/ruby-2.2.4/bin
 - /home/glory/.rvm/bin
 - /usr/local/heroku/bin
 - /home/glory/.rbenv/plugins/ruby-build/bin
 - /home/glory/.rbenv/shims
 - /home/glory/.rbenv/bin

您正在使用rbenv和RVM。

不要这样做。

rbenv documentation具体说:

  

兼容性说明: rbenv 与RVM不兼容。在安装rbenv之前,请确保完全卸载RVM并从shell初始化文件中删除对它的任何引用。

我建议您使用

删除它们
rm -rf ~/.rbenv
rvm implode

然后从〜/ .bashrc,〜/ .bash_profile和〜/ .profile文件中删除它们的初始化行。

然后选择一个或另一个,rbenv或RVM,并仅重新安装那个。这将迫使您重新安装您想要使用的红宝石以及相关的宝石,但它也会彻底修复混乱。

答案 1 :(得分:-1)

我认为从启动应用程序的位置开始,ruby版本会出现问题。 切换到应用程序创建的其他ruby版本。 您可以使用以下版本管理器切换到不同的版本

  1. RVM
  2. rbenv
  3. 用法:rvm使用{ruby-version}