rvm implode
Tags: ruby, rvm, chruby
Published: 2023-08-23 23:44:03

## tl;dr
`rvm implode && brew install chruby && brew install ruby-install`

## Intro

As a ruby developer, I grew to love [rvm](https://rvm.io/). It does so much it seems like magic ... in fact, it may actually be magic. But after a multi-year love affair, its flaws became apparent.

```
$ rvm disk-usage gemsets
Gemsets Usage: 5.4G
```

*Yikes.* My first thought was to try to figure out how much disk space each individual gemset was using and remove some of them. I read the docs and didn't find anything there, so I went to the [mailing list](https://groups.google.com/d/topic/rubyversionmanager/-shEn7e1Li4/discussion), and [mpapis](https://twitter.com/mpapis), being the amazing guy that he is, got back to me right away. Alas, no simple way to do this.

Then I started to think a little bit more about why I was even using gemsets. Typing `bundle exec` can get pretty annoying, but it isn't the end of the world. I had a separate gemset for each app to keep my gem dependencies from conflicting, but that's what bundler is for. What really annoyed me was that when I would `rm -rf` an app's code, I'd forget to remove the gemset and I had a bunch of orphaned gemsets out there hogging disk space.

`rvm implode`

## The many talents of rvm
Like I mentioned, rvm does a lot:

1. Compilation/installation of rubies
2. Switching between rubies
3. Separation of gem dependencies

The problem is that it's trying to be all things to all people. There are some 20,000 lines of shell script in rvm, and each of these things can be accomplished much more efficiently by a single purpose-built tool.

## 1. s/rvm/ruby-install
`brew install ruby-install`

For installing rubies, I'm using [ruby-install](https://github.com/postmodern/ruby-install), written by the amazing [postmodern](https://twitter.com/postmodern_mod3). There's also [ruby-build](https://github.com/sstephenson/ruby-build) which works almost as well, but I love the fact that ruby-install lets me use shortcuts like I did with rvm so I can just do `ruby-install ruby 2.0` and get the latest 2.0 patchlevel rather than having to specify manually like with ruby-build.

ruby-install is dead-simple and does exactly what it promises. By default it installs rubies to `~/.rubies` although you can install them wherever your heart desires. I stuck with the default.

## 2. s/rvm/chruby
`brew install chruby`

For switching rubies, I'm using [chruby](https://github.com/postmodern/chruby), again, by the unstoppable [postmodern](https://twitter.com/postmodern_mod3). Some folks prefer [rbenv](https://github.com/sstephenson/rbenv), but I love the simplicity of chruby. Plus, it (optionally) does auto-switching like rvm, so if a directory has a `.ruby-version` file, it will switch to that version automagically.

chruby will automatically look in `~/.rubies`, where ruby-install puts them, so no configuration needed there. just add three lines to your `.bashrc` or `.zshrc`:

```bash
source /usr/local/opt/chruby/share/chruby/chruby.sh # mandatory
source /usr/local/opt/chruby/share/chruby/auto.sh # if you want auto-switching
chruby ruby-2.0 # to set a default ruby
```