Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails console: in `require': cannot load such file -- readline (LoadError)

I've got some errors in my Rails app and I'm trying to start the Rails console by issuing following command:

rails console

No matter what I try, I'm always getting the same error:

/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError)
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `<top (required)>'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands/console.rb:3:in `require'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands.rb:37:in `require'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands.rb:37:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I've really tried every possible solution I found on the net, as many people encounter the same error. Unfortunately, nothing seems to work. When I try the following command:

ruby /usr/local/rvm/src/ruby-2.1.1/ext/readline/extconf.rb

I get following output

checking for tgetnum() in -lncurses... yes
checking for readline/readline.h... yes
checking for readline/history.h... yes
checking for readline() in -lreadline... no
checking for readline() in -ledit... no
checking for editline/readline.h... no
*** /usr/local/rvm/src/ruby-2.1.1/ext/readline/extconf.rb failed ***

Indicating that something is missing, but installing readline with apt-get doesn't make a difference either. I'm guessing it could have something to do with incompatible gem versions, as the console worked briefly some time ago. Are there any known version issues with readline? Very much people seem to have encountered problems with this gem.

like image 782
Flock Dawson Avatar asked Apr 07 '14 14:04

Flock Dawson


2 Answers

If you are running Rails 4.x it is possible that Spring is causing this issue.

Try stopping the Spring process bundle exec spring stop

Then run bundle exec rails c

like image 181
Edgar Ortega Avatar answered Oct 26 '22 18:10

Edgar Ortega


I finally found a solution. It was a conjunction of several issues (gem versions, conflicting readline libraries).

Firstly, I refetched the readline lib

sudo apt-get install libreadline-dev

Then I uninstalled ruby

rvm remove 2.1.1

I installed ruby again

rvm install 2.1.1

I told RVM to use the default (2.1.1) Ruby

rvm use default

I reinstalled Rails and readline

gem install rails
gem install readline

I got an error again launching the console, but a slightly different one:

/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `require':  /usr/local/lib/libreadline.so.6: undefined symbol: UP - /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/x86_64-linux/readline.so (LoadError)
    from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/completion.rb:9:in `<top (required)>'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands/console.rb:3:in `require'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands.rb:37:in `require'
    from /opt/mammie/web/icosole/vendor/bundle/ruby/2.1.0/gems/railties-3.1.3/lib/rails/commands.rb:37:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

So following this instructions (http://vkarthickeyan.wordpress.com/2012/02/16/mysql-symbol-lookup-error-usrlocalliblibreadline-so-6-undefined-symbol-up/), I got it to work:

cd /usr/local/lib
mkdir temp
mv libreadline* temp
ldconfig
apt-get update

Thanks to hunterboerner for the help!

like image 42
Flock Dawson Avatar answered Oct 26 '22 19:10

Flock Dawson