HOWTO make readline and history work with irb and rails console on OS X Yosemite

Here’s how to make readline (including control-R reverse search) and command history work with both irb and the Rails console with rbenv and OS X Yosemite (10.10.4).

You need to install Readline first, as OS X ships with libedit instead. You also need to make sure rbenv knows where you put readline.

1. Install rbenv and the ruby-build plugin.

2. Download GNU Readline. Install it:

tar zxf readline-6.3.tar.gz && rm readline-6.3.tar.gz cd readline-6.3 configure && make && sudo make install cd .. rm -rf readline-6.3

3. Install Ruby using rbenv:

RUBY_CONFIGURE_OPTS="--with-readline-dir=/usr/local" rbenv install 2.2.2

3. Add these lines to your ~/.irbrc file:

require 'irb/completion' require 'irb/ext/save-history' IRB.conf[:SAVE_HISTORY] = 10000 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-history"

This gets everything working in irb. To make things work in Rails, you need to:

4. Install the rails and rb-readline gems:

gem install rails rb-readline

5. Add rb-readline to your Rails’ app’s Gemfile:

group :development, :test do gem 'rb-readline' end

and run bundle install.

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *