Uninstall Multiple Versions of Multiple Ruby Gems


07-31-2012


Filed under: ruby, bash, gem

Let’s say you have multiple versions of spree gems installed and want to get rid of the older versions.

zlu@zlu-mba: gem list spree
spree (1.1.3, 1.0.0, 1.0.0.rc2)
spree_api (1.1.3, 1.0.0, 1.0.0.rc2)
spree_auth (1.1.3, 1.0.0, 1.0.0.rc2)
spree_cmd (1.1.3, 1.0.0, 1.0.0.rc2)
spree_core (1.1.3, 1.0.0, 1.0.0.rc2)
spree_dash (1.1.3, 1.0.0, 1.0.0.rc2)
spree_promo (1.1.3, 1.0.0, 1.0.0.rc2)
spree_sample (1.1.3, 1.0.0, 1.0.0.rc2)

Instead of doing this a bunch of times (for different gems and versions):

gem uninstall spree -v 1.0.0

Do this:

gem uninstall spree{,_api,_auth,_cmd,_core,_dash,_promo,_sample} -v {1.0.0, 1.0.0.rc2}

This is a feature of bash shell - brace expansion.