Skip to content

Instantly share code, notes, and snippets.

@zanshin
Forked from nixpulvis/gem-reset
Created June 10, 2013 13:49
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 zanshin/5748841 to your computer and use it in GitHub Desktop.
Save zanshin/5748841 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
`gem list -d`.split(/\n\n^(?=\w)/).each do |data|
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/)
name = match[:name]
versions = match[:versions].split(', ')
if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/)
next if match[1].empty? # it's the only version if this match is empty
versions.delete(match[1] || versions[0])
end
versions.each { |v| system "gem uninstall -Ix #{name} -v #{v}" }
end
@zanshin
Copy link
Author

zanshin commented Jun 10, 2013

Run without saving by copying one of these into your shell.

CURL curl -Ls raw.github.com/gist/5748841 | ruby
WGET wget -qO- raw.github.com/gist/5748841 | ruby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment