Last active
September 22, 2024 20:05
-
-
Save nixpulvis/5042764 to your computer and use it in GitHub Desktop.
Remove all non default gems. For ruby 2.0.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
-:4:in split': invalid byte sequence in US-ASCII (ArgumentError) from -:4:in
Works fine, nice job, thank you!
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I'm fork and fixed.
Exclude my favorite gems during gem uninstall.
If you have a gem that want to keep, it is preferable to exclude them by fork.
https://gist.github.com/zchee/d2f100f1322fd6322a44
curl -Ls https://gist.githubusercontent.com/zchee/d2f100f1322fd6322a44/raw/2b129e3136baf839d9fb530fd215800a733c1dc8/gem-reset | ruby
@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
GitHub appears to have changed the way raw URLs work.
Updated: Run without saving by copying one of these into your shell.
CURL:
curl -Ls https://gist.github.com/nixpulvis/5042764/raw/7daa611e707f1884eb701551464bfd1dc9e7a953/gem-reset | ruby
WGET:
wget -qO- https://gist.github.com/nixpulvis/5042764/raw/7daa611e707f1884eb701551464bfd1dc9e7a953/gem-reset | ruby