LiJung
LiJung

Reputation: 7949

Ruby gem running forever and Ruby, gem path error

I have problem with my gem and Ruby command, I think it's because of path problem.

gem install jekyll

takes for a long time to run, and outputs an error message:

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)

I entered which ruby, which output:

/usr/local/bin/ruby

If I enter which gem, it prints out:

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}
}

Enter whereis gem, prints out:

/usr/bin/gem

Does anyone know how to fix it? I've tried for a long time and get confused.


UPDATE:

Enter gem env I got:

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/

enter 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 <[email protected]>, Michal Papis <[email protected]> [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:       ""

Upvotes: 0

Views: 544

Answers (1)

the Tin Man
the Tin Man

Reputation: 160551

The first thing I see that is a "really bad thing" when using RVM is:

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"

Even with how Stack Overflow formats this you can see that the RVM initialization isn't correct. RVM must be the first thing in your path. Look in your ~/.bash_profile or ~/.bashrc file and adjust the PATH manipulations so it comes first, then close the terminal window and reopen it. Checking the PATH should look something like:

"/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"

The path is the chain of directories used by your shell when looking for a command. Your current path is telling the shell to find commands in /usr/local/bin and /usr/local/sbin first, which means it will find all Ruby-related commands in that directory first, which are NOT the ones that RVM installed for you.

Fixing the RVM initializer so it runs at the right point in your ~/.bash_profile or ~/.bashrc is the first step.

Your RVM is out of date too. Every couple weeks you should run rvm get stable to make sure you've got the latest settings and bug-fixes. Once your path is straightened out you can run that.

The error:

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

is indicative of internet problems between you and your server. Usually that will be fixed on its own. If it doesn't heal itself in a reasonable time, try restarting your machine, which will give the IP stack a chance to restart and flush all its caches; Though that code is well tested, there are still times it can lose it's mind and do dumb things. The reset is a poke in its eye which gets its attention. If THAT doesn't fix it consider calling your ISP.


I be able to use Ruby, that I've downloaded from brew? How can I set my gem path to the right path?

Deal with things in the right order. You can't use your Ruby as it's currently configured because your gems are not correctly associated with the right Ruby version and any changes you make to the Ruby installations will only result in confusion and mayhem. Once you have the path corrected and RVM running correctly, then it's a very simple RVM command to enable other Homebrew Rubies:

rvm use system --default

At that point, RVM will step out of the way and your other Rubies will be accessible via the PATH chain. You have to manage which Ruby version will be executed at that point.

Avoiding that hassle is why we use RVM or rbenv; They can easily install multiple Ruby versions and let you switch between them with a simple command, or even automatically when you chdir into a directory, if you set them up to do so. Brew only muddies the water, and trying to use a Brew installed Ruby was the source of your problem, so I'd recommend seriously rethinking that decision.

Finally, because you don't seem to understand what you're doing, and you're on Mac OS X, I'd recommend fixing this path problem, then backing away from the computer, READ ALL THE RVM PAGES until you REALLY understand what it does, then carefully make changes. Don't trust what other sites say about installing RVM, trust what the RVM authors say first. The authors know what works best for using it.

You might want to look into using JewelryBox also.

Upvotes: 2

Related Questions