Skip to content

Instantly share code, notes, and snippets.

@bjhess
Created November 30, 2009 19:59
Show Gist options
  • Save bjhess/245694 to your computer and use it in GitHub Desktop.
Save bjhess/245694 to your computer and use it in GitHub Desktop.
#! /usr/bin/ruby
# Ever update/reinstall ruby and need to bring all your old gems,
# including old versions to the new environment? Just output your
# gem list to gem_list.txt and run it through this script.
install_all = false
File.open("gem_list.txt").each do |line|
# coderay (0.8.273, 0.8.260, 0.7.4.215)
match_data = /(\w+) \((.+)\)/.match(line)
gem_name, versions = match_data[1], match_data[2]
versions = versions.split(', ')
versions.each do |version|
if !install_all
puts "Install #{gem_name} (v #{version}) gem? (y/n/a)"
response = gets
next if response =~ /^n/i
install_all = true if response =~ /^a/i
end
puts "Installing #{gem_name} (v #{version})"
system "sudo gem install #{gem_name} -v #{version}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment