12

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.

Community
  • 1
  • 1
toftis
  • 1,070
  • 9
  • 26
  • 2
    please report a bug for rvm (https://github.com/wayneeseguin/rvm/issues) - this should be handled by installing proper libraries / headers by autolibs - but requires some debugging to make sure it works properly – mpapis Aug 04 '13 at 14:41
  • I having the same problem in one server but not in the other.. the only difference I'm seeing is the `rbenv` version `rbenv 0.4.0-74-g95a039a` works without the `rb-readline` gem workaround, and the one with `rbenv 0.4.0-75-gbe5e1a` is not working. Adding the gem `rb-radline v0.4.2` to my Gemfile made the trick as @deepender-singla said. – fguillen Jan 15 '14 at 15:05

2 Answers2

8

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.

marikhu
  • 51
  • 5
Deepender Singla
  • 999
  • 9
  • 28
  • Thanks for the answer. I will not accept it though, since it does not answer why it is not working in 0.5 or if anybody is working to fix this. My main point is that a central library like this should work out of the box. – toftis Aug 09 '13 at 08:23
  • okey , I understand I thought may be you can use this in time being so that your work doesn't get affected. – Deepender Singla Aug 09 '13 at 08:38
  • @Magne can you write problem in detail here, I will try to answer. thanks – Deepender Singla Dec 10 '14 at 04:21
  • After some back and forth, I got it working by running `gem uninstall rb-readline` and then using only `gem 'rb-readline'` in my Gemfile and running `bundle install`. That would install rb-readline version 0.5.1 which purportedly has solved the bug. – Magne Dec 10 '14 at 08:36
  • Thanks for the willingness to assist though, @DeependerSingla :) – Magne Dec 10 '14 at 08:37
1

The above answer works well. Either install the gem system wide

gem install rb-readline

or by adding the above gem to your projects Gemfile

gem 'rb-readline'

But if you guys don't want to include any extra gems in your Gemfile and you have downloaded ruby using the source file do the following:-

sudo apt-get install libreadline-gplv2-dev libncurses5-dev
cd ~/.rvm/src/ruby-1.9.2-p180/
make clean
cd ~/.rvm/src/ruby-1.9.2-p180/ext/readline
ruby extconf.rb
cd ~/.rvm/src/ruby-1.9.2-p180/
make
make install

Use sudo if required :). Hope this helps :)

sahilbathla
  • 519
  • 3
  • 10