irb readline support on Leopard

Written . Tagged OS X, Ruby.

The irb (Interactive Ruby) that ships with OS X Leopard does not have readline support. Instead it uses libedit.

This means that things like ⌃R for reverse history search don’t work. More importantly to me, you can’t use non-ASCII characters like Swedish “å”, “ä” and “ö”.

Compiling your own Ruby (with readline) is one solution. If you just want ctrl+R, macosxhints has another.

The solution I’m currently using is the work of jptix, a regular on the ##textmate IRC channel. He asked me to blog about it, so here it is.

Get MacPorts and install readline (you must specify +universal, even on Intel):

1
sudo port install readline +universal

Get the Ruby extension for readline:

1
svn co http://svn.ruby-lang.org/repos/ruby/tags/v1_8_6_111/ext/readline/ readline

Apply a small patch to readline/extconf.rb:

1
curl http://pastie.textmate.org/pastes/168767/download | patch readline/extconf.rb

Compile and install the extension. You likely need the OS X developer tools, or have a C compiler from elsewhere:

1
2
3
4
cd readline
ruby extconf.rb
make
sudo make install

All döne. Håppy häcking.