<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>loopkid: uninstall all gems</title>
    <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>professional procrastinator</description>
    <item>
      <title>uninstall all gems</title>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo gem uninstall --a --ignore-dependencies .+
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You may have to execute it twice before all gems are gone. If the command doesn&amp;#8217;t work then try this shell script (thanks to &lt;a href="http://snipt.net/melzz/uninstall-all-ruby-gems/"&gt;melzz&lt;/a&gt;):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/bin/bash

GEMS=`gem list --no-versions`
for x in $GEMS ; do gem uninstall $x; done
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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&amp;#8217;re going to have to find a different way. I have tested this on Mac OS X, if you&amp;#8217;re using Linux you&amp;#8217;d want to replace the &lt;code&gt;-E&lt;/code&gt; with an &lt;code&gt;-r&lt;/code&gt; and escape the asterik with a backslash as pointed out in the comments.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem list --no-versions | sed -E '/^(*|$)/d' &amp;gt; installed_gems
sudo gem uninstall --a --ignore-dependencies .+
cat installed_gems | xargs sudo gem install
rm installed_gems
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Sat, 31 May 2008 16:15:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:59735da9-134a-4533-b809-10d68678ac62</guid>
      <author>Stefan</author>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems</link>
      <category>English</category>
      <category>Ruby</category>
      <trackback:ping>http://loopkid.net/articles/trackback/7567</trackback:ping>
    </item>
    <item>
      <title>"uninstall all gems" by Timo</title>
      <description>&lt;p&gt;One liner for those of you who were unable to get the regexp working:
gem list &amp;#8211;no-version | xargs gem uninstall -aIx&lt;/p&gt;</description>
      <pubDate>Wed, 06 Apr 2011 10:13:51 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:a49b6d7e-eddb-4ad8-94a2-cfd3035c750a</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-160450</link>
    </item>
    <item>
      <title>"uninstall all gems" by Don Smith</title>
      <description>&lt;p&gt;&lt;a href="http://gist.github.com/526232"&gt;http://gist.github.com/526232&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</description>
      <pubDate>Mon, 16 Aug 2010 03:40:03 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:1a9dd010-d97c-44d3-bbdb-037896d64629</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-139826</link>
    </item>
    <item>
      <title>"uninstall all gems" by boourns</title>
      <description>&lt;p&gt;Ivan, yours worked great, thanks.  on ubuntu 10.04, trying to downgrade rails 3 beta to 2.3.8 by reinstalling everything&lt;/p&gt;</description>
      <pubDate>Wed, 02 Jun 2010 02:34:37 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:1782782e-ed26-45f9-aa80-82dca607bed4</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-137419</link>
    </item>
    <item>
      <title>"uninstall all gems" by Ivan Storck</title>
      <description>&lt;p&gt;this is the version that worked for me: &lt;code&gt; gem list --no-versions | xargs --interactive sudo gem uninstall -a -I&lt;/code&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 22 Dec 2009 04:57:06 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:0b5364f7-a953-400b-b891-f1c90413bb4d</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-114369</link>
    </item>
    <item>
      <title>"uninstall all gems" by stefan</title>
      <description>&lt;p&gt;the problem might be, that you&amp;#8217;re using an irregular dash. try entering the statement manually instead of copy &amp;amp; pasting it and see if it works! good luck!&lt;/p&gt;</description>
      <pubDate>Wed, 23 Sep 2009 16:50:34 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:4205300d-fe8f-43f1-940f-07214a310fcd</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-80700</link>
    </item>
    <item>
      <title>"uninstall all gems" by acatl</title>
      <description>&lt;p&gt;hi, any idea why im getting this error: &lt;/p&gt;

&lt;p&gt;ERROR:  While executing gem &amp;#8230; (Gem::InstallError)
    cannot uninstall, check &lt;code&gt;gem list -d .+&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m on OS X and ran the command:
sudo gem uninstall &amp;#8211;a &amp;#8211;ignore-dependencies .+&lt;/p&gt;</description>
      <pubDate>Wed, 23 Sep 2009 16:34:10 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:95f17725-b60f-47d6-acd2-783dda0014a4</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-80689</link>
    </item>
    <item>
      <title>"uninstall all gems" by Stefan</title>
      <description>&lt;p&gt;Thank you for your helpful comment, I have added a notice to the posting!&lt;/p&gt;</description>
      <pubDate>Sun, 15 Mar 2009 20:09:04 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:102322a6-3e0a-42cd-8c77-a89e58dcd9f2</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-38881</link>
    </item>
    <item>
      <title>"uninstall all gems" by stumble</title>
      <description>&lt;p&gt;Also, for Linux, you need to escape the * in the regexp:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem list --no-versions | sed -r '/^(\*|$)/d' &amp;gt; installed_gems&lt;/code&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 15 Mar 2009 19:03:05 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:cde5b73c-51f4-4cd8-9526-c1890e4ad1af</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-38873</link>
    </item>
    <item>
      <title>"uninstall all gems" by Stefan</title>
      <description>&lt;p&gt;I have edited the posting. If you haven&amp;#8217;t already wiped your gems, this might be what you&amp;#8217;re looking for.&lt;/p&gt;</description>
      <pubDate>Thu, 03 Jul 2008 22:52:48 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:b7b79f21-32bc-4d1a-b606-fde271081a1f</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-8509</link>
    </item>
    <item>
      <title>"uninstall all gems" by Bharat Ruparel</title>
      <description>&lt;p&gt;Thank you.  This saves me all kinds of time.  Is there an automated way of installing gems so  rebuilding is just as easy?&lt;/p&gt;</description>
      <pubDate>Thu, 03 Jul 2008 17:00:05 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:1ec5f834-b0b3-4b2d-bb2b-664f0ade6a0d</guid>
      <link>http://loopkid.net/articles/2008/05/31/uninstall-all-gems#comment-8505</link>
    </item>
  </channel>
</rss>

