Speeding Up Your Console When Using rbenv
by Dan Barron Friday, January 25th, 2013I’m a huge fan of rbenv as a way to manage multiple Ruby installs on my system. It’s a huge step up from the ever popular RVM. Not that I don’t genuinely appreciate what RVM has done for the Ruby community, I just prefer the much cleaner way rbenv handles things. However, this isn’t a post about which Ruby version manager is best.
It was recently brought to my attention that rbenv can slow down the launch of a new console instance by ~1 second (call the National Guard, the world is ending!). Given that time is constantly of the essence, a fix was in order.
The Problem
Typically, when setting up rbenv for the first time, you’re required to append the following init driver to the end of your .profile/.bashrc/.zshrc file:
eval "$(rbenv init -)"Since my shell of choice is ZSH, I’ve appended this to the end of my .zshrc file. However, this is the source of our problem. Turns out, every time you spin up a new Terminal instance, rbenv runs it’s ‘rehash’ command, which, according to the rbenv documentation, “Installs shims for all Ruby executables known to rbenv”. This is helpful when you install either a new version of Ruby or certain gems that either have native bindings or install a shell command, but we don’t need to run this EVERY time we start a new shell, do we? Of course not.
The Solution
A quick fix can solve all our woes! Change the line to be:
eval "$(rbenv init - --no-rehash)"And voilà! Faster startup time and no headaches. It’s like Christmas all over again! Just remember that you’ll have to run ‘rbenv rehash’ manually any time you install a new Ruby or a gem that requires it. Happy hacking!