Skip to content

Instantly share code, notes, and snippets.

@wfarr
Created October 21, 2009 04:38
Show Gist options
  • Select an option

  • Save wfarr/214878 to your computer and use it in GitHub Desktop.

Select an option

Save wfarr/214878 to your computer and use it in GitHub Desktop.
#!/bin/env ruby
rbgem = `which gem`.strip
output = `#{rbgem} list --local`
output.each do |line|
matches = line.match(/([A-Z].+) \(([0-9\., ]+)\)/i)
if matches
gem_name = matches[1]
versions = matches[2].split(', ')[1..-1]
versions.each do |ver|
cmd = "#{rbgem} uninstall #{gem_name} -i -v #{ver}"
puts "#{gem_name}-#{ver}"
system cmd
end
end
end
puts "Uninstalled all old gems!" if output !=~ /,/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment