Fixing readline for the Ruby on Rails console

Fixing readline for the Ruby on Rails console
$ rails console
/home/user/.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/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/completion.rb:9:in `'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in `require'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in `'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:20:in `require'
    from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.9/lib/rails/commands.rb:20:in `'
    from script/rails:6:in `require'
    from script/rails:6:in `
'
The problem is that Ruby is somehow not cofigured to load the readline library and thus cannot run its console. This is a downside of using a language specific package manager, seperate from your operating system's package manager.

First you need to install libreadline5 and libncurses5. I can't see why ncurses would be needed, but I am too lazy to uninstall it and check if it still works without the library. Using Apt on Ubuntu/Debian:

    $ sudoaptitudeinstall libreadline5-dev libncurses5-dev
   

Next you want to go configure and rebuild Ruby's readline extension. I am using RVM and so Ruby exists in ~/.rvm/src/ruby-1.9.2-p180/ for me. This can differ for you but running which ruby should tell you where yours is.
cd ~/.rvm/src/ruby-1.9.2-p180/ext/readline
ruby extconf.rb
make
make install
  
Depending on your setup you might need to install it by running sudo make install instead. That is it! Now Ruby on Rails' console should load as intended.

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Interview Question on Ruby on Rails