rvm implode
lightweight ruby version switching ftw
tl;dr
rvm implode && brew install chruby && brew install ruby-install
Intro
As a ruby developer, I grew to love rvm. 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, and 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:
- Compilation/installation of rubies
- Switching between rubies
- 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, written by the amazing postmodern. There's also 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, again, by the unstoppable postmodern. Some folks prefer 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
:
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
3. s/rvm/bundler
Saying goodbye to gemsets:
You might also be interested in these articles...
Startup Founder | Engineering Leader with an MBA