Fixing Ruby pry/readline under Ubuntu

Disclaimer: I don’t know why this error occurred on my office installation of Ubuntu 10.04 but this is what I did to solve it.

After installing pry (with a RVM ruby version) and wanting to run it I got the following error block:


mallibone@troulwd0062:~$ pry
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:11: warning: already initialized constant DEFAULT_HOOKS
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:22: warning: already initialized constant DEFAULT_PRINT
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:47: warning: already initialized constant SIMPLE_PRINT
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:56: warning: already initialized constant CLIPPED_PRINT
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:61: warning: already initialized constant DEFAULT_EXCEPTION_HANDLER
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:67: warning: already initialized constant DEFAULT_EXCEPTION_WHITELIST
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:70: warning: already initialized constant DEFAULT_PROMPT
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:81: warning: already initialized constant SIMPLE_PROMPT
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:83: warning: already initialized constant SHELL_PROMPT
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:90: warning: already initialized constant NAV_PROMPT
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:106: warning: already initialized constant DEFAULT_CONTROL_D_HANDLER
/home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:120: warning: already initialized constant DEFAULT_SYSTEM
/home/users/mallibone/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- readline (LoadError)
        from /home/users/mallibone/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/lib/pry.rb:163:in `'
        from /home/users/mallibone/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/users/mallibone/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from /home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/bin/pry:12:in `rescue in '
        from /home/users/mallibone/.rvm/gems/ruby-1.9.3-p125@global/gems/pry-0.9.8.2/bin/pry:8:in `'
        from /home/users/mallibone/.rvm/gems/ruby-1.9.3-p125/bin/pry:19:in `load'
        from /home/users/mallibone/.rvm/gems/ruby-1.9.3-p125/bin/pry:19:in `'

Now the line that shows us the error is this one:


/home/users/mallibone/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- readline (LoadError)

So we have a readline error. No need to click onto that link and go off reading just keep in mind that this library does the following:

The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in.

But back to the original problem, how do we get it running? Well in your Ruby installation there is a extconf.rb file which according to the read-me: The Readline module provides interface for GNU Readline.. So what we have to do now is update our installation i.e. update this wrapper module. I’m using RVM so I found the file under the path[1]:

/home/users/mallibone/.rvm/src/ruby-1.9.3-p125/ext/readline

To update our wrapper cd into your readline directory and run the following commands:


ruby extconf.rb
make
sudo make install

The typing pry into the shell resulted in the rewarding response:

[1] pry(main)>

Update

Under Ubuntu 11.10 you have to further install libreadline library to get pry and AFAIK the rails console. One way to do this is by the following lines (again using RVM):


rvm uninstall 1.9.3-p125
sudo apt-get install libreadline-dev
rvm install 1.9.3-p125 --with-readline-dir=/usr/include/readline

Thank you megas for pointing out this issue under Ubuntu 11.10 and providing a good explanation and solution to the problem.

Resources:

Readline LoadError Solution
GNU Readline

[1] If you don’t know where or what kind of installation you have type cd / into your command line and then

find . -name "extconf.rb"

This should show you where your extconf.rb file is but may take a while looking for it.

Advertisements