Today I was running a ZAP session, and it stopped halfway through because I had run out of disk space. When I started to analyze where space was being used, I found around 20 GB that were used by RVM. I like to keep the ruby version of my projects as up-to-date as possible, so it’s very common that I install new versions as soon as they are released.
If I’m not mistaken, RVM does not share gemsets between ruby versions, so I had 10 rubies installed, each with a copy of the gemsets of a rails application. Yeah, a lot. I took a quick look to the documentation and came up with a one-liner I’d like to keep for future-me:
rvm remove $(rvm ls | grep ruby- | cut -d " " -f4 | grep -v $(cat .ruby-version) | paste -sd "," -)
Essentially, it uninstalls all rubies except the one in .ruby-version. I had never used paste before, and it was pretty straightforward.
Happy coding!