RVM and Textmate in harmony

One side effect of Ruby's popularity is the proliferation of ruby interpreters that can now execute ruby code, which is generally seen as a good thing, as a sign of a healthy community. However, keeping track of all these versions of Ruby, especially when testing gets harder as each new version of Ruby is released, so to help alleviate this problem Wayne E. Seguin released Ruby Version Manager, or RVM to it's friends last year.

RVM does some clever voodoo with symbolic links and suchlike on your box to let you switch between versions of Ruby very easily on the command line simply by typing RVM use ruby-version when you want to use a particular flavour of Ruby. So If I wanted to run MacRuby instead of the usual version of Ruby 1.8.7 that uses the MRI Interpreter, I'd simply check what versions of Ruby I had installed on my box like so :

[7:52]:rvm list

   jruby-1.4.0 [ [x86_64-java] ]
   macruby-nightly [ ]
   ree-1.8.7-2010.01 [ ]
=> ruby-1.8.7-tv1_8_7_249 [ x86_64 ]
=> (default) ruby-1.8.7-tv1_8_7_249 [ x86_64 ]
   system [ x86_64 i386 ppc ]

And then say which Ruby I want to use for the rest of the session I have open:

[7:52]:rvm use macruby-nightly

  Now using macruby nightly

And if I wanted to switch back, I'd just type

[7:54]:rvm use default        

Now using default ruby.

This is extremely handy, except if you're using Textmate, which by default, will happily use a version of Ruby that pays no attention to your version switching japery, making testing and development rather less fun.

Fortunately, there are now some tools to make RVM work with everyone's favourite mac only OS X editor now. Here's how to to make the two work together easily:

First of all tell RVM to setup your symlink:

    rvm 1.8.7 --symlink textmate

Now, you'll need to tell Textmate to use this version of Ruby instead by a) setting a shell variable, and then forcing Textmate to use this Ruby instead, by moving the Builder class, that normally sets up it's Ruby shell environment:

Here's where you should set your shell variable in Textmate:

Once you have that, swap out the Builder as mentioned before, then restart Textmate.

    cd /Applications/TextMate.app/Contents/SharedSupport/Support/lib/ ; mv Builder.rb Builder.rb.backup

And that should be about it. You can easily test that this worked in Textmate by opening a new file containing only the following code snippet:


... then either saving the file with a .rb extension, or set the syntax colouring for Ruby, then hitting command +

If it worked, you should see something like this:

If not, don't despair - there's lots of useful docs on the RVM site itself, and the irc channel, #RVM is full of wonderfully helpful types.

Now go, armed with this knowledge and make Textmate and RVM to play nicely together again.

Copyright © 2020 Chris Adams
Powered by Cryogen
Theme by KingMob