Using TextMate with rbenv

Over the last week I reinstalled OS X Lion on my 2008 MacBook. The speed-up has been noticeable, the cruft from four years of continued use is gone, and I finally have a chance to set right things I should have fixed long ago.

One of these things is my choice of ruby version manager. For a while I’ve been using rvm, but I really haven’t enjoyed the gemset experience, and things…tend to go wrong. Messing around with it to get various scripts to work was a bit of a pain.

So this time around, I decided to go with rbenv. It has its own problems, though, and despite some desperate googling, I still had to fix some things on my own. In an attempt to help others, here’s a list of problems I had, and their solutions:

Missing openssl

Upon trying to run a rails server, ActiveRecord would fail because it couldn’t find the openssl library.

This one was easy-ish to fix: simply re-compile my ruby with openssl included. Since I’d installed openssl via homebrew, I figured it’d be hanging around usr/local - I wasn’t far wrong:

>  ~  cd /usr/local 
>  ls
Cellar etc       lib       texlive
Library   bin       include   share
>  cd Cellar && ls
autoconf      libgpg-error  multimarkdown rbenv
git           libksba       openssl       ruby-build

I’m compiling using ruby-build, which can be installed via brew and clicks in nicely to rbenv:

CONFIGURE_OPTS="--with-openssl-dir=/usr/local/Cellar/openssl" rbenv install 1.9.3-rc1

Replace the path to openssl with your own if you build from scratch. Problem: solved.

TextMate problems

My editor of choice doesn’t support rbenv out of the box - this is easy enough to test by running:


Without any further editing, this will run the system ruby (1.8.7 for me, a little bit out of date). The top google hit is helpful (especially its comments) helps greatly. There’s one case where it doesn’t help - if your file starts with a hashbang. You can edit which ruby the program is using by changing the TM_RUBY variable (in Settings > Advanced > Shell Variables), but I like using hashbangs at the start of my ruby files:

!/usr/bin/env ruby

It looks like this will cause TextMate to override the TM_RUBY variable and instead run whatever the environment wants it to run. The solution here is to make sure that TextMate’s PATH contains the directories holding:

  1. Your rbenv shims, and
  2. rbenv itself

For me, these are ~/.rbenv/shims (not ~/.rbenv/bin as suggested by the uberfork article above) and /usr/local/bin. So I just make sure my PATH starts with /Users/jan/.rbenv/shims:/usr/local/bin and everything works, exceedingly wel.

Bonus section: picking your rbenv version

If you want to be really clever, the variable RBENV_VERSION will let you set which version of ruby you want to run. Otherwise, I imagine, it defaults to rbenv global.