Andreas Yankopolus
Andreas Yankopolus

Reputation: 931

Script to update RVM-based ruby install and gems

A couple searches didn't turn up an obvious way to update my RVM-based ruby and gems so I whipped up the following script. The desire is to get a list of currently installed gems, update to the new ruby, pull those gems forward, then clean out the old versions of everything. I'm posting it here for feedback, since I don't see an easy way to test it and I'm barely competent at ruby and mostly clueless about RVM.

#!/usr/bin/env ruby

module RubyUpdate
  def self.cmd(str, cmd)
    puts str
    retval = %x(#{cmd})
    throw(SystemCallError, cmd) unless $? == 0
    return retval
  end

  def self.update
    gems = self.cmd %Q(Getting list of installed gems...), %Q(gem list | cut -d ' ' -f 1)
    self.cmd %Q(Updating ruby...), %Q(\\curl -L https://get.rvm.io | bash -s stable --ruby)
    self.cmd %Q(Reloading...), %Q(rvm reload)
    self.cmd %Q(Updating gems..), %Q(gem update #{gems.gsub("\n", " ")})
    self.cmd %Q(Cleaning up gems...), %Q(gem cleanup)
    self.cmd %Q(Reloading...), %Q(rvm reload)
    self.cmd %Q(Cleaning up ruby...), %Q(rvm cleanup all)
  end
end

begin
  RubyUpdate::update
  puts "Update successful!"
rescue SystemCallError => e
  puts "Update failed!"
  puts e
end

Upvotes: 0

Views: 112

Answers (1)

mpapis
mpapis

Reputation: 53178

you should use:

rvm get stable
rvm upgrade current ruby

Upvotes: 1

Related Questions