I am BARRY HESS > Blog

Ruby Console Spacebar Problems

Since early this summer, I have had a severely annoying problem with my Ruby consoles (irb and script/console). My spacebar quit functioning, making quick testing of Ruby and Rails functionality quite limited and in some cases impossible. I’ll give you two versions of my story. First the short version.

Readline, you bane of my existence

Helvetica Notebook
Photo by Stewf

Long, long ago I installed my Mac OS X Rails environment as described in the excellent Hivelogic instructions, written by Dan Benjamin. Life was good and my environment was isolated in /usr/local. But then in June the spacebar stopped working and I became unhappy. I tried posting the problem to a few Ruby targeted groups, both near and far, but no one had a suggestion.

After lots of head-banging (not this kind, unfortunately), I solved the problem by removing my /usr/local version of readline, which I installed through the Hivelogic instructions. These are the files I removed:

Since the Hivelogic instructions explicitly connect the Ruby install with the /usr/local version of readline, I needed to recompile Ruby. These steps assume you did not remove the original source you downloaded when installing Ruby at the outset:

cd /usr/local/src/ruby-1.8.6
make distclean
./configure --prefix=/usr/local --enable-pthread --enable-shared
sudo make install

Notice in the ./configure line I did not include the --with-readline-dir=/usr/local switch shown in the Hivelogic instructions. (If you have deleted the Ruby source files, merging the above with the Hivelogic instructions should get things done for you.)

Recently a similar issue appeared with my MySQL console. I suppose that’s the next hurdle.

My detailed path to uncovering a readline problem

Path Along the Viottolone - Giardino di Boboli
Photo by IceNineJon

I tried to resolve this spacebar problem a couple times in the past few months, but recently I became motivated to finally remove this monkey from my back. I posted something to the great Rails forum, which was the first community that offered some ideas.

First I logged in to OS X under The Wife’s account and found that irb did not have any spacebar issues. Useful information. In my local account, I tried running irb under the csh, tcsh, and zsh shells, and it had the same problem throughout. Thanks to B.J. Clark for those ideas.

So then I dug into my ~/.bash_profile file, eliminating line-by-line until I made my irb spacebar problem go away. I found that if I changed this export statement:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

To this (by removing /usr/local/bin):

export PATH="/usr/local/sbin:/usr/local/mysql/bin:$PATH"

The irb spacebar problems went away again. Thanks to Ryan Bates for that tip.

Naturally, if I remove /usr/local/bin from my PATH, I’m reverting to OS X’s default Ruby and irb binaries. This is not really a solution; I need a later version of Ruby on the system. Something must be corrupted in my /usr/local area.

Many tries at reinstalling Ruby

Thinking I just needed a freshly minted version in place, I tried reinstalling several versions of Ruby in a couple different ways:

For “fun,” I copied over the default version of Ruby (/usr/bin/ruby) over to /usr/local/bin/ruby. This eliminated the spacebar problem, but it still just was not a solution. Since my install of OS X has Ruby version 1.8.2, I tried:

That’s when I started thinking it wasn’t a Ruby issue. Yes, I know I’m a genius so don’t bother commenting along those lines. Perhaps it was an irb binary issue. Again, I copied over the default version of irb to /usr/local/bin/irb. Spacebar problems disappeared. However, script/console failed, and command history was unavailable (that’s what readline is for).

Crazy little thing called readline

Next I reverted back to the proper /usr/local irb binary and called with irb --noreadline. The spacebar worked again, this time using my original /usr/local version of irb and Ruby.

Thinking it must be a readline problem, I upgraded readline to 5.2 and even reinstalled Ruby 1.8.6. In this case, irb with readline still did not recognize my spacebar.

Confident that readline was the issue, I happened on the solution outlined at the beginning of this article. I imagine this sends me back to the OS X system default readline. Technically I no longer have control over all stuff that’s being used in my coding environment. But I think I’ll leave it be for now. Readline is low-impact, and it really seems unlikely that I’ll be needing the latest and greatest version anytime soon. My guess is the problem is in some specific OS X configuration thing that needs to be done when compiling readline, and frankly I just don’t have the energy.