Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
Last active October 5, 2020 15:21
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save nixpulvis/5042764 to your computer and use it in GitHub Desktop.
Save nixpulvis/5042764 to your computer and use it in GitHub Desktop.
Remove all non default gems. For ruby 2.0.0
#!/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
@pvdb
Copy link

pvdb commented Jun 4, 2018

@nixpulvis - any ideas/suggestions for not only skipping the so-called default gems, but also the so-called bundled gems? see https://stdgems.org/ for their respective definitions.

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