Sunday, October 17, 2010

Update Ruby Gems - CentOS

Circular dependencies suck. It's a really great thing that the entire package management system for Ruby is written with Ruby, until you need to update Ruby using said system when said system itself needs to be updated.

I'm currently trying to update Ruby and RubyGems on CentOS via yum and life has not been fun. Step 1, rubygems wasn't present, so I installed with yum. That went fine, except it installed version 0.9.2 of gems. Hmm, Ok, no big deal, I can run gem update --system. Nope, fail:

me@host$ sudo gem update ruby
Updating installed gems...
ERROR:  While executing gem ... (Gem::RemoteSourceException)
    HTTP Response 302


Great, rubygems changed their URL since 0.9.2 and apparently whatever http tool gems uses can't follow redirects. Well, after some debugging and total failure to find any help online, I discovered that gems maintains a sources file /usr/lib/ruby/gems/1.8/gems/sources-0.0.1/lib/sources.rb that lists the domain(s) of its repositories. Well, let me just change that to the new URL

module Gem
  @sources = ["http://rubygems.org"]
  def self.sources
    @sources
  end 
end


I ran the command again. STILL getting the 302. What the heck??? Alright, after some more debugging, I discover it's trying to download a yaml description file located at http://rubygems.org/yaml. This loads fine in my browser, but a little telnet shows that I'm being redirected (obvious hint from the 302 earlier).

[me@host]$ telnet rubygems.org 80
Trying 72.4.120.124...
Connected to rubygems.org (72.4.120.124).
Escape character is '^]'.
GET /yaml HTTP/1.1
host: rubygems.org

HTTP/1.1 302 Found
Date: Mon, 18 Oct 2010 05:46:40 GMT
Server: Apache/2.2.3 (Red Hat) mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5 Phusion_Passenger/2.2.15
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15
X-UA-Compatible: IE=Edge,chrome=1
X-Runtime: 0.000895
Location: http://production.s3.rubygems.org/yaml
Content-Length: 0
Status: 302
Vary: Accept-Encoding
Content-Type: text/html


Hey, look! There's the redirect URL! A little update and I'm good to go.

module Gem
  @sources = ["http://production.s3.rubygems.org"]
  def self.sources
    @sources
  end
end


Then run,
[me@host]$sudo gem update --system
Updating RubyGems...
Attempting remote update of rubygems-update
Successfully installed rubygems-update-1.3.6
Installing ri documentation for rubygems-update-1.3.6...
Installing RDoc documentation for rubygems-update-1.3.6...
Could not find main page README
Could not find main page README
Could not find main page README
Could not find main page README
Updating version of RubyGems to 1.3.6
Installing RubyGems 1.3.6
ERROR:  Expected Ruby version >= 1.8.6, is 1.8.5
RubyGems system software updated

### Damn
### Maybe update ruby with gem? 

[me@host]$ sudo gem update ruby
Updating installed gems...
Attempting remote update of ruby
ERROR:  While executing gem ... (Gem::GemNotFoundException)
    Could not find ruby (> 0) in any repository


Nope, no go. So it looks like I am manually installing Ruby from the source since the yum repository only has Ruby as modern as version 1.8.5 dated 2006-08-25!! Isn't Ruby and Rails supposed to make life easier??

3 comments:

  1. I'm just going through this same pain. Ironically, it's to get Puppet (+mod_passenger+activerecord) installed, to make our other servers more manageable. The puppetmaster will be the least manageable server we have, at this rate!

    ReplyDelete
  2. Thank you for posting this. On Ubuntu, the file to change is /var/lib/gems/1.8/gems/sources-0.0.1/lib/sources.rb

    ReplyDelete
  3. For some closure... I had 1.8.6 (not 1.8.5) and your efforts worked on my issue (as I had .9.2 of rubygems on my machine and the install was driving me nuts)

    summary...

    installed ruby gems 9.2....
    get 302 error when try to install rails...
    try to update rubygems... failed because of 302 again... this is contrary to rubygems website..
    then I realize no such solution exists. After some reading, I update my sources.rb file here file.... ruby/gems/1.8/gems/sources-0.0.1/lib/sources.rb

    as the website a Sheep Apart suggests: http://asheepapart.blogspot.com/2010/10/update-ruby-gems-centos.html

    Then I update rubygems with two lines:
    gem install rubygems-update
    update_rubygems


    Then I can finally install rails....

    PHEW... maybe you can change your instructions to start with rubygems 1.3.6 (or whatever) to avoid the hassle.

    ReplyDelete