Ruby gem永远运行和Ruby,gem路径错误

时间:2013-11-20 15:32:34

标签: ruby gem rvm

我的gem和Ruby命令有问题,我认为这是因为路径问题。

gem install jekyll

需要很长时间才能运行,并输出错误消息:

ERROR:  Could not find a valid gem 'jekyll' (>= 0)

Unable to download data from https://rubygems.org/ - too many connection resets(https://s3.amazonaws.com/production.s3.rubygems.org/latest_specs.4.8.gz)

我输入which ruby,输出:

/usr/local/bin/ruby

如果我输入which gem,则打印出来:

gem () {
  typeset result
  (
    typeset rvmrc
    rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc") 
    if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
    then
      rvm_rvmrc_files+=("${rvm_prefix}/.rvmrc") 
    fi
    for rvmrc in "${rvm_rvmrc_files[@]}"
    do
      [[ -s "${rvmrc}" ]] && source "${rvmrc}" || true
    done
    unset rvm_rvmrc_files
    command gem "$@"
  ) || result=$? 
  hash -r
  return ${result:-0}
}

输入whereis gem,打印出来:

/usr/bin/gem

有谁知道如何修复它?我已经尝试了很长时间而感到困惑。


更新:

输入gem env我得到了:

RubyGems Environment:
    - RUBYGEMS VERSION: 2.0.3
    - RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-darwin13.0.0]
    - INSTALLATION DIRECTORY: /Users/lijung/.rvm/gems/ruby-1.9.3-p374
    - RUBY EXECUTABLE: /usr/local/Cellar/ruby/2.0.0-p247/bin/ruby
    - EXECUTABLE DIRECTORY: /Users/lijung/.rvm/gems/ruby-1.9.3-p374/bin
    - RUBYGEMS PLATFORMS:
      - ruby
      - x86_64-darwin-13
    - GEM PATHS:
       - /Users/lijung/.rvm/gems/ruby-1.9.3-p374
       - /usr/local/bin/gem
    - GEM CONFIGURATION:
       - :update_sources => true
       - :verbose => true
       - :backtrace => false
       - :bulk_threshold => 1000
    - REMOTE SOURCES:
       - https://rubygems.org/

输入rvm info

ruby-1.9.3-p374:

  system:
    uname:       "Darwin chi.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64"
    system:      "osx/10/x86_64"
    bash:        "/usr/local/bin/bash => GNU bash, version 4.2.37(2)-release (i386-apple-darwin12.2.0)"
    zsh:         "/bin/zsh => zsh 5.0.2 (x86_64-apple-darwin13.0)"

  rvm:
    version:      "rvm 1.18.3 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "9 months 18 days 11 hours 37 minutes 54 seconds ago"

  ruby:
    interpreter:  "ruby"
    version:      "2.0.0p247"
    date:         "2013-06-27"
    platform:     "x86_64-darwin13.0.0"
    patchlevel:   "2013-06-27 revision 41674"
    full_version: "ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin13.0.0]"

  homes:
    gem:          "/Users/lijung/.rvm/gems/ruby-1.9.3-p374"
    ruby:         "/Users/lijung/.rvm/rubies/ruby-1.9.3-p374"

  binaries:
    ruby:         "/usr/local/bin/ruby"
    irb:          "/usr/local/bin/irb"
    gem:          "/usr/local/bin/gem"
    rake:         "/usr/local/bin/rake"

  environment:
    PATH:         "/usr/local/bin:/usr/local/sbin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374@global/bin:/Users/lijung/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Postgres.app/Contents/MacOS/bin"
    GEM_HOME:     "/Users/lijung/.rvm/gems/ruby-1.9.3-p374"
    GEM_PATH:     "/usr/local/bin/gem"
    MY_RUBY_HOME: "/Users/lijung/.rvm/rubies/ruby-1.9.3-p374"
    IRBRC:        "/Users/lijung/.rvm/rubies/ruby-1.9.3-p374/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

1 个答案:

答案 0 :(得分:2)

使用RVM时,我首先看到的是“非常糟糕的事情”:

PATH: "/usr/local/bin:/usr/local/sbin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374@global/bin:/Users/lijung/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Postgres.app/Contents/MacOS/bin"

即使使用Stack Overflow格式化,您也可以看到RVM初始化不正确。 RVM 必须是您路径中的第一件事。查看〜/ .bash_profile或〜/ .bashrc文件并调整PATH操作,使其首先出现,然后关闭终端窗口并重新打开它。检查PATH应该类似于:

"/Users/lijung/.rvm/gems/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/gems/ruby-1.9.3-p374@global/bin:/Users/lijung/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/lijung/.rvm/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Postgres.app/Contents/MacOS/bin"

路径是shell在查找命令时使用的目录链。您当前的路径告诉shell首先在/ usr / local / bin和/ usr / local / sbin中查找命令,这意味着它将首先在该目录中找到所有与Ruby相关的命令,这些命令不是RVM安装的命令。你。

修复RVM初始化程序,使其在〜/ .bash_profile或〜/ .bashrc中的正确位置运行是第一步。

您的RVM也已过时。每隔几周您就应该运行rvm get stable以确保您拥有最新的设置和错误修复程序。一旦你的道路被理顺,你就可以运行它。

错误:

Unable to download data from https://rubygems.org/ - too many connection resets...

表示您和您的服务器之间存在互联网问题。通常这将自行修复。如果它没有在合理的时间内自行修复,请尝试重新启动计算机,这将使IP堆栈有机会重新启动并刷新其所有缓存;尽管该代码经过了充分的测试,但有时它仍然可能会失去理智并做出愚蠢的事情。重置是一个引起注意的眼睛。如果 THAT 无法修复,请考虑致电您的ISP。


  

我可以使用Ruby,我从brew下载了吗?如何将宝石路径设置为正确的路径?

以正确的顺序处理事情。您不能使用当前配置的Ruby,因为您的gem与正确的Ruby版本没有正确关联,并且您对Ruby安装所做的任何更改只会导致混乱和混乱。一旦你纠正了路径并且RVM正确运行,那么它就是一个非常简单的RVM命令来启用其他的Homebrew Rubies:

rvm use system --default

此时,RVM将逐步退出,您的其他Rubies将通过PATH链访问。您必须管理将在那时执行的Ruby版本。

避免麻烦是我们使用RVM或rbenv的原因;他们可以轻松地安装多个Ruby版本,并允许您使用简单的命令在它们之间切换,甚至可以在chdir进入目录时自动切换,如果您将它们设置为这样做。只喝水,并尝试使用Brew安装的Ruby是你的问题的根源,所以我建议认真重新思考这个决定。

最后,因为你似乎不明白你在做什么,而且你在Mac OS X上,我建议修复这个路径问题,然后退出计算机,阅读所有的RVM PAGES 直到您真的了解它的作用,然后仔细进行更改。不要相信其他网站关于安装RVM的内容,请相信RVM作者首先说的话。作者知道什么最适合使用它。

您可能还希望使用JewelryBox