Skip to content

Instantly share code, notes, and snippets.

@jez
Forked from IanVaughan/uninstall_gems.sh
Last active December 27, 2022 22:06
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save jez/cc2ba08062c6183a489c to your computer and use it in GitHub Desktop.
Save jez/cc2ba08062c6183a489c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Originally from https://gist.github.com/IanVaughan/2902499
#
# authors: Ian Vaughan
# Jacob Zimmerman
#
# usage: uninstall_gems [<version> ...]
#
# examples:
# Uninstall all gems in all ruby version
# uninstall_gems
#
# Uninstall all gems in ruby 2.1.3
# uninstall_gems 2.1.3
#
# Uninstall all gems in the current ruby version
# uninstall_gems $(rbenv version-name)
uninstall() {
list=`gem list --no-versions`
for gem in $list; do
gem uninstall $gem -aIx
done
gem list
gem install bundler
}
if [ "$@" ]; then
RUBIES="$@"
else
#rbenv versions --bare
RBENVPATH=`rbenv root`
echo $RBENVPATH
RUBIES=`ls $RBENVPATH/versions`
fi
# Don't clobber existing .ruby-version file
if [ -f ./.ruby-version ]; then
RUBY_VERSION="$(cat ./.ruby-version)"
fi
for ruby in $RUBIES; do
echo '---------------------------------------'
echo $ruby
rbenv local $ruby
uninstall
done
# Restore old .ruby-version file if there was one
if [ "$RUBY_VERSION" ]; then
echo "$RUBY_VERSION" > ./.ruby-version
else
rm ./.ruby-version
fi
@kyletolle
Copy link

Here were the steps I used to run this command on my machine:

cd ~/code/github
git clone git@gist.github.com:cc2ba08062c6183a489c.git uninstall_gems
cd uninstall_gems
chmod +x uninstall_gems.sh
./uninstall_gems.sh

@ag0os
Copy link

ag0os commented Jul 8, 2021

Works great, thanks!

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