Last Updated: February 25, 2016
·
1.434K
· aaronjensen

Keep your gemsets clean

If you're using rvm gemsets along with bundler you can uninstall old versions of gems by running:

bundle clean --force

You only want to do this if you're using a gemset per project, otherwise you'll blow away gems other projects need. If you stick to this you can automate this with a bash alias:

alias bi='bundle install && ( ( [ `rvm-prompt g` ] && bundle clean --force ); true )'

Now when you run bi it will bundle install and do a clean only if you're currently in a gemset.

EDIT: In practice, this got a little annoying as it made switching branches that upgraded gems more time consuming.

To combat this I decided to make it only clean gems 10% of the time.

alias bi='bundle install && ( ( [ $RANDOM -gt 29490 ] && [ `rvm-prompt g` ] && bundle clean --force ); true )'

How did I decide on 10%? Just randomly. I wanted something low because I don't need the gemset always to be clean, this will ensure that it happens occasionally on active projects which is what i really want. Game theory ;)