Frodo Larik

Wonderful worldwide web

Cleanup old Gems, but not rails and friends

If you’re like me and have several rails applications in different rails versions, it’s difficult to just run a gem cleanup, because it would mean all your old rails gems will also be deleted.

You don’t want that, but you also don’t want to clean them up one by one.

Here’s easy way to do it from your bash command line:

for g in $(sudo gem cleanup --dryrun \
   | awk '$1=="Dry" && $6!~/^(rails|action(mailer|webservice|pack)|active(resource|support|record))/ { print $6}' \
   | sed -E -e 's/-([0123456789].?)+$//g' \
   | sort --unique --ignore-case); do
      sudo gem cleanup $g
done

Just copy the code above in your terminal, make sure you’ve got sudo rights.

You might get warnings about dependencies, just say no and rerun the code if needed.

Author: Frodo Larik