Accented chars in IRB with RVM and ruby 1.8.7

Since moving to Mac, I always find it surprising that the default Mac OS X Ruby and IRB doesn’t allow inputs with accented characters. So, you cannot do

name = "George Guimarães"

This is annoying for brazilians and anyone who uses non-ASCII characters. The problem is that the default Ruby in Mac OS X isn’t linked against readline. A simple solution is to compile readline on your system, and then compile your own ruby binaries. A better one is to use tools that automate this process.

This post by Christopher Sexton uses homebrew to compile readline-0.6 but compiles ruby by hand. Since we love RVM, we’ll use it too.

If you use Homebrew (and you *should*), just do

brew install readline
brew link readline

Beware: linking readline into your system may break other tools that depends on readline source to compile. It was harmless on my system.

Ok, so now we want to build a new ruby and irb binaries. I wanted to use ruby 1.8.7-p248, so:

rvm install 1.8.7-p248 -C --enable-shared,--with-readline-dir=/usr/local

This tells the configure script to enable shared library linking (it is the default), and to search for readline in /usr/local (homebrew has just linked readline there). You may have to use --force if you already have this ruby version compiled. Newer versions of RVM do not need --force.

Now you can use accented and unicode characters on keyboard input in IRB using ruby 1.8.7.

And you? Do you have any tricks with IRB that you may want to share? Do you use Wirble, Utility Belt or others?

5 responses to “Accented chars in IRB with RVM and ruby 1.8.7”

  1. iain says:

    nice article!

    anyway, I use wirble, hirb and awesome_print, and a colorful IRB-prompt:

    http://gist.github.com/368237

  2. Roger Leite says:

    Boa George!

    My irbrc is here http://gist.github.com/276299
    I use irb/completion, a “home made” history, awesome print (if exists) and rails2 logger.

    success!

  3. iain says:

    Yeah, cool, but I got a Rails 3 logger! 😛

  4. Roger Leite says:

    Now I got too! ;D

  5. John says:

    Actually it would be much better to build / install the RVM readline package and build your RVM rubies against that instead of linking a brew / macports readline. This way nothing breaks, not even the stuff you don’t know about.

    The reason for all this nonsense is that OS X does not use readline but a similar tool with a different name. Forgot the name but its really a pain. Anyhow – RVM has a solution for this: http://rvm.beginrescueend.com/packages/readline/