Applies to: Ruby 1.8.7, compiled from source, on OS X 10.6 (Snow Leopard).
I’ve been working on a side project that deals with Japanese text in Ruby. I installed rtranslate, a gem that gives me programmatic access to Google Translate. I wanted to try it out in irb.
>> require 'rtranslate'
So far so good.
Here’s where I started to run into problems. I changed the input mode to Japanese and tried to enter はい (hai). All I got was beeping – irb wouldn’t let me enter any Japanese characters at all. I tried pasting from somewhere else – also a no go.
Long story short: by default, Ruby links against editline instead of GNU readline, and editline doesn’t support multi-byte characters. If I started irb with the –noreadline option, it worked fine, but then none of the arrow keys worked. Highly annoying.
I read five different articles      that fixed variants of the problem; none of the solutions worked fully for me. My machine is running Snow Leopard, and I had installed Ruby 1.8.7 from source following the Hivelogic directions. So if you’re in the same boat, here’s how you get multi-byte input working:
1. Install GNU readline.
curl -O ftp://ftp.gnu.org/gnu/readline/readline-6.0.tar.gz
tar xzvf readline-6.0.tar.gz
sudo make install
The –prefix in the configure line is crucial.
2. Recompile Ruby, pointing at the new readline. I still had the Ruby source directory in ~/src from when I compiled it the first time (this is a relatively new laptop). If you don’t, you can just download it again.
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz
tar xzvf ruby-1.8.7-p174.tar.gz
./configure --enable-shared --with-readline-dir=/usr/local
sudo make install
3. My profile had gotten out of whack, so I had to add this line (again) to ~/.bash_profile:
Now I can enter multi-byte characters into irb, or copy them in from elsewhere. Now I can get on with what I was actually going to do.
>> require "rtranslate"
>> Translate.t("はい", "JAPANESE", "ENGLISH")