Skip to content

Instantly share code, notes, and snippets.

@excid3
Created January 9, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save excid3/89312203ebddc3bc9b81 to your computer and use it in GitHub Desktop.
Save excid3/89312203ebddc3bc9b81 to your computer and use it in GitHub Desktop.
require "open-uri"
RUBYGEMS_VERSIONS = {
"1.8" => {
"url" => "https://github.com/rubygems/rubygems/releases/download/v1.8.30/rubygems-update-1.8.30.gem",
"filename" => "rubygems-update-1.8.30.gem"
},
"2.0" => {
"url" => "https://github.com/rubygems/rubygems/releases/download/v2.0.15/rubygems-update-2.0.15.gem",
"filename" => "rubygems-update-2.0.15.gem"
},
"2.2" => {
"url" => "https://github.com/rubygems/rubygems/releases/download/v2.2.3/rubygems-update-2.2.3.gem",
"filename" => "rubygems-update-2.2.3.gem"
}
}
current_rubygems_version = `gem --version`
puts "You currently have Rubygems #{current_rubygems_version} installed."
version = current_rubygems_version[0..2]
url = RUBYGEMS_VERSIONS[version]["url"]
filename = RUBYGEMS_VERSIONS[version]["filename"]
puts "Downloading Rubygems update (#{filename})..."
open(filename, 'wb') { |file| file << open(url).read }
puts "Installing #{filename}..."
`gem install --local #{filename}`
puts "Updating Rubygems..."
`update_rubygems --no-ri --no-rdoc`
puts "Cleaning up..."
`gem uninstall rubygems-update -x`
puts "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment