What is wrong with readline?

toftis picture toftis · Aug 4, 2013 · Viewed 7.2k times · Source

I set up a Rails environment three times with different OSes and with Rails 3 and 4. It goes smoothly until I open a console to type some Ruby, or inspect my database with rails console or rails dbconsole. I get something similar to:

$ rails console
/home/tobias/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/completion.rb:9:in       `require': no such file to load -- readline (LoadError)
from /home/tobias/.rvm/rubies/ruby-1.9.2-p18080/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in `require'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gemsems/railties-3.0.9/lib/rails/commands/console.rb:3:in `<top (required)>'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.commandsrb:20:in `require'
from /home/tobias/.rvm/gems/ruby-1.9.2-p180/gems/railsilties-3.0.9/lib/rails/commands.rb:20:in `<top (required)>'
from scriptt/rails:6:in `require'
from script/rails:6:in `<main>'

This is from "Fixing readline for the Ruby on Rails console". This solved my problem twice.

Now I am using Rails 4 and Ruby 2 and it went well until:

mto@mto-mint-vm ~/src/rpg $ rails console
/home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/completion.rb:9:in `require': /usr/local/lib/libreadline.so.6: undefined symbol: UP - /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux/readline.so (LoadError)
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/completion.rb:9:in `<top (required)>'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:3:in `require'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:53:in `require'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:53:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

The blog did not help me this time. Stackoverflow has relevant questions:

The last one suggested to add gem 'rb-readline' to my gemfile. I added the line, ran bundle install and got this:

mto@mto-mint-vm ~/src/rpg $ rails console
Loading development environment (Rails 4.0.0)
/home/mto/.rvm/scripts/irbrc.rb:30:in `block in <top (required)>': uninitialized constant Readline (NameError)
/home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/input-method.rb:150:in `gets': uninitialized constant IRB::ReadlineInputMethod::Readline (NameError)
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:472:in `block (2 levels) in eval_input'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:624:in `signal_status'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:471:in `block in eval_input'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:190:in `call'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:190:in `buf_input'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:105:in `getc'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/slex.rb:206:in `match_io'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/slex.rb:76:in `match'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:290:in `token'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:266:in `lex'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:237:in `block (2 levels) in each_top_level_statement'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in `loop'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in `catch'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/ruby-lex.rb:232:in `each_top_level_statement'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:488:in `eval_input'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:397:in `block in start'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:396:in `catch'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb.rb:396:in `start'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `start'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `start'
    from /home/mto/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

"Rails 3: uninitialized constant IRB::ReadlineInputMethod::Readline (NameError) in Heroku" solved the problem by tying the gem to version 0.4.2. I had 0.5.0.

Why can a simple library, which has such a central place in Rails, and in Ruby as well I guess, cause so much pain? Is anything being done to make this easier?

This is just a library for reading lines from the console, right? Where is it going wrong in the above examples? I would like to know why and not what and how.

Answer

Deepender Singla picture Deepender Singla · Aug 7, 2013

You can do this and it worked for me:

gem install rb-readline

And add the following line to your project's Gemfile:

gem 'rb-readline', '~> 0.4.2'

I am locking gem to this version as updated version will give some error.