Yesterday I switched my main development environment over to chruby. I feel that this is fitting to blog about because I’m currently writing an article about both rbenv and chruby. Now before we go any further, I want you to keep in mind that this is just an opinion. So if you would like to discuss with me the pros and cons of each, go right ahead in the comments below
Installing chruby was as easy as:
brew install chruby and then
echo "source /usr/local/share/chruby/chruby.sh" >> ~/.zshrc. Then I uninstalled rbenv quickly so as not to have them conflict (I’m not sure if they play nice together, but I don’t have a reason to find out) and went on my merry way.
Now I know what you’re thinking, “Jesse, chruby doesn’t automatically use rubies from rbenv.” You’re absolutely right. So I just appended the following to my
.zshrc and reloaded zsh.
I know, we all like auto Ruby switching too. So here’s my
.zshrc for chruby.
# chruby source /usr/local/share/chruby/chruby.sh # all stuff below is optional source /usr/local/share/chruby/auto.sh RUBIES+=(~/.rbenv/versions/*)
Now that we’ve got that setup, let’s rock!
$ chruby 2.1.2 jruby-1.7.12 mruby-1.0.0 * ruby-2.1.3 # "*" denotes current version
As you can see, I’ve got a few Rubies here. I can switch easily now with a simple
chruby 2.1.2 or
chruby jruby. I also installed ruby-install (
brew install ruby-install), but it’s your choice.
Why I switched.
My first exposure to chruby was when first trying out nitrous.IO. I tried running
rbenv but it wasn’t there, so I did some reading and found out that they were using chruby. I found this super interesting because nitrous.IO is the new “hip thing”, right? So they must have a reason for this.
More reading and I started to like this idea of a simple lightweight Ruby version switcher. I previously thought rbenv was the lightweight alternative to a bloated RVM. But I realized that while rbenv is awesome, it still keeps things a little slower with its shims than chruby with its… well, simple Ruby switching. This means that with rbenv, running any RubyGem will be just a little bit slower than chruby because the command has to go through shims.
# rbenv $ jekyll jekyll => executable shim => rbenv finds proper ruby => ruby code runs # chruby $ jekyll jekyll => ruby code runs (already has the proper ruby loaded)
I also love the simplicity of chruby. It feels even more UNIX–y than rbenv did, which I really like. Don’t think I’m hating on command line suites though, I git and jekyll. I just feel like something as simple as changing Ruby versions should be as unobtrusive, yet useful, as possible.
Anyway, chruby is pretty cool. I don’t see myself going back to rbenv anytime soon, but if I do you’ll hear about it. Make sure to keep an eye out at SitePoint Ruby for my article on advanced chruby and rbenv usage!
Next post: Outsmarting Panera's WiFi