uninstall all gems 31. May 2008
To perform batch operations in MacPorts you can use the predefined pseudo-portnames. RubyGems has no such thing, but instead it can handle regular expressions. So to uninstall all gems of your default RubyGems installation you can simply issue the following command.
sudo gem uninstall --a --ignore-dependencies .+
For some weird reason in my case I had to call it twice, but then all gems where gone.
Bharat Ruparel asked in the comments if there is a way to automatize the reinstallation of the gems. Yes, there is. This solution generates a file containing a list of all the gems and after removing all gems reads the gem names from this file to reinstall them. The solution does not however honor the installed version of the gems, so if you care about the versions you’re going to have to find a different way. I have tested this on Mac OS X, if you’re using Linux you’d want to replace the -E with an -r and escape the asterik with a backslash as pointed out in the comments.
gem list --no-versions | sed -E '/^(*|$)/d' > installed_gems
sudo gem uninstall --a --ignore-dependencies .+
cat installed_gems | xargs sudo gem install
rm installed_gems
Thank you. This saves me all kinds of time. Is there an automated way of installing gems so rebuilding is just as easy?
I have edited the posting. If you haven’t already wiped your gems, this might be what you’re looking for.
Also, for Linux, you need to escape the * in the regexp:
gem list --no-versions | sed -r '/^(\*|$)/d' > installed_gemsThank you for your helpful comment, I have added a notice to the posting!