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 .+
You may have to execute it twice before all gems are gone. If the command doesn’t work then try this shell script (thanks to melzz):
#!/bin/bash
GEMS=`gem list --no-versions`
for x in $GEMS ; do gem uninstall $x; done
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!
hi, any idea why im getting this error:
ERROR: While executing gem … (Gem::InstallError) cannot uninstall, check
gem list -d .+I’m on OS X and ran the command: sudo gem uninstall –a –ignore-dependencies .+
the problem might be, that you’re using an irregular dash. try entering the statement manually instead of copy & pasting it and see if it works! good luck!
this is the version that worked for me:
gem list --no-versions | xargs --interactive sudo gem uninstall -a -IIvan, yours worked great, thanks. on ubuntu 10.04, trying to downgrade rails 3 beta to 2.3.8 by reinstalling everything
http://gist.github.com/526232
Thanks!