47
[gkaykck@main myApplication]$ rails console
/usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `require': no such file to load -- readline (LoadError)
    from /usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `require'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `require'
    from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:20:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I have installed rails 3 on ruby 1.9.2p136, which is ok i guess. But i cannot start rails console and it gives me the error i copied. The apps worked great with ruby 1.8.7 and i never saw an error like this.

Any ideas what it could be?

winfred
  • 3,053
  • 1
  • 25
  • 16
gkaykck
  • 2,347
  • 10
  • 35
  • 52
  • 1
    How have you installed 1.9.2? You need to install readline first and compile ruby with readline support. Also, from the stacktrace, it looks like it's using 1.9.1... – idlefingers Feb 07 '11 at 15:05
  • What happens when you type irb for 1.9.2? Can you require 'readline'? – fifigyuri Feb 07 '11 at 15:08
  • @idlefingers i installed 1.9.2 from source and if i ask for ruby -v it says "ruby 1.9.2p136 (2010-12-25 revision 30365) [i686-linux]". I don't know about readline but except irb everything works normally – gkaykck Feb 07 '11 at 15:15
  • @fifigyuri no i cannot require readline, so i think problem is there – gkaykck Feb 07 '11 at 15:16
  • 3
    [Philippe's answer in a similar post](http://stackoverflow.com/a/8973725/356895) worked for me: `gem install rb-readline` and add `gem 'rb-readline'` to your Gemfile. – JJD Aug 07 '12 at 14:57
  • Found this: http://happy-coding.com/require-no-such-file-to-load-readline-loaderror/ – disco crazy Sep 16 '13 at 09:32

10 Answers10

49

Apparently ubuntu and ruby don't always catch dependencies like they should.

From the first google hit (yeah, I clicked on this stack-overflow in place #2 before checking out the first result.)

Navigate to the Ruby source and enter:

sudo apt-get install libreadline5-dev
cd ext/readline
ruby extconf.rb
make
sudo make install

So, if you're on another distro, make sure you install readline somehow (source/package), then run make/install on extconf from the source. I tried what gkaykck suggested of course but got this without readline already on my system.

$ ruby extconf.rb
checking for tgetnum() in -lncurses... no
checking for tgetnum() in -ltermcap... no
checking for tgetnum() in -lcurses... no
checking for readline/readline.h... no
checking for editline/readline.h... no
winfred
  • 3,053
  • 1
  • 25
  • 16
29

Recipe for those who use rvm:

rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr

In more details about it on https://rvm.io/packages/readline/

shiva
  • 434
  • 4
  • 21
Nikolay Moskvin
  • 1,038
  • 1
  • 16
  • 27
11

If you want another solution to this problem do this.

sudo apt-get install libreadline6

Then in your gem file add:

gem 'rb-readline'

Then

bundle install

And you should be all set.

Philip
  • 6,827
  • 13
  • 75
  • 104
5

I'd recommend using rvm (Ruby Version Manager) to manage your different versions of Ruby and switch between them. It does a pretty good job of compiling the various versions for you too. You can even create per-directory .rvmrc files to tell rvm what version of ruby to use in which directory (as well as use per-project gem sets if you want!)

futuremint
  • 724
  • 4
  • 5
  • i don't like using rvm neither using multiple ruby or rails versions or even any software's multiple versions at once, i don't think it CAN be a good practice. – gkaykck Feb 07 '11 at 15:18
  • 6
    You don't need to install multiple versions of Ruby. Even if you only use one, it's worth switching to RVM. – mhmhmhmh Feb 07 '11 at 15:35
  • 1
    @gkaykck rvm saved me so much effort and time. It simplifies not only ruby version management, but also maintaining different gemsets for various ruby projects. – fifigyuri Feb 07 '11 at 18:40
  • ok i know that it simplifies things but, things should be simple, not simpler. Ruby and Rails means there will be really much things running under hood, and i want to see under the hood whenever possible with this kind of errors or stuff. Otherwise i'll only learn how to use rails and ruby, but i'll not learn ruby on rails in depth – gkaykck Feb 07 '11 at 19:53
  • 2
    @gkaykck: Use RVM. Trust us on this one. – zetetic Feb 07 '11 at 21:07
  • 1
    @gkaykck RVM isn't some wicked voodoo magic or anything. Its basically just a command-line utility that does some path management for your installed rubies & gems. You can still go poking around your ruby installation, except its even easier to find because you'll find the whole ruby tree in ~/.rvm. – futuremint Feb 08 '11 at 01:16
  • Concur, RVM is great. I've needed to use different versions of ruby and this has been very valuable. I know how you feel about ruby, I also want to learn about what's going on "under the hood." But if that kept me from doing anything other that writing bare ruby I wouldn't use gems. And then I'd be sad. :-( – Tass Jan 06 '12 at 22:41
  • RVM is outdated and very error-prone. Use rbenv instead: https://github.com/sstephenson/rbenv – Houen Aug 15 '13 at 10:42
5

First of all uninstall every ruby version you have.

After that display rvm requirements:

rvm requirements

You will get something like:

Requirements for Linux ( DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu 11.10" )

NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)   
This is the *original* / standard Ruby Language Interpreter  
      'ree'  represents Ruby Enterprise Edition  
      'rbx'  represents Rubinius  

bash >= 4.1 required curl is required git is required (>= 1.7 for
ruby-head) patch is required (for 1.8 rubies and some ruby-head's).

To install rbx and/or Ruby 1.9 head (MRI) (eg. 1.9.2-head), then you
must install and use rvm 1.8.7 first.

Additional Dependencies: 
# For Ruby / Ruby HEAD (MRI, Rubinius, & REE), install the following:
  ruby: /usr/bin/apt-get install build-essential openssl libreadline6 
  libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev 
  libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev 
  ncurses-dev automake libtool bison subversion

# For JRuby, install the following:
  jruby: /usr/bin/apt-get install curl g++ openjdk-6-jre-headless
  jruby-head: /usr/bin/apt-get install ant openjdk-6-jdk

# For IronRuby, install the following:
  ironruby: /usr/bin/apt-get install curl mono-2.0-devel

Install all dependencies via apt-get.
After that install ruby 1.8.7. This version is required if you plan to use ruby 1.9.x
Now you can install ruby 1.9.3:

rvm pkg install readline
rvm remove 1.9.3
rvm install 1.9.3 --with-readline-dir=$rvm_path/usr

Note that you dont even need to install readline package via rvm if you had installed it using apt-get.

JJD
  • 50,076
  • 60
  • 203
  • 339
Pikachu
  • 774
  • 13
  • 15
3

With CentOS 6:

Remember we are working from the ruby install dir, for me it was:

   /opt/ruby-1.9.3-p194/ext/readline

If you see the following output, then readline is not installed:

$ ruby extconf.rb 
checking for tgetnum() in -lncurses... no
checking for tgetnum() in -ltermcap... no
checking for tgetnum() in -lcurses... no
checking for readline/readline.h... no
checking for editline/readline.h... no

To install with RPM:

yum install readline-devel

Then build it:

ruby extconf.rb 
make
sudo make install
Sooth
  • 2,834
  • 23
  • 26
  • that also worked for me on CentOS5. i've used the solution from this source, though: http://niwos.com/2011/04/15/fixing-ruby-readline-errors-on-centos/ – Evgeniya Manolova Sep 26 '13 at 14:03
2

Adding in the Gemfile

gem 'rb-readline'

and then bundle install

did the trick for me

Steve Lng C
  • 1,204
  • 1
  • 8
  • 9
1

Solution is to go to the source folder you compiled ruby => ext => readline than

ruby extconf.rb
make
sudo make install
JJD
  • 50,076
  • 60
  • 203
  • 339
gkaykck
  • 2,347
  • 10
  • 35
  • 52
0

If you're using RVM you can re-make readline. This fixed the issue for me. Instructions here:

no such file to load -- readline (Load Error)

Community
  • 1
  • 1
superluminary
  • 47,086
  • 25
  • 151
  • 148
0

use rvm remove to remove all ruby installed. do a "which ruby" if you still get something, you need to reinstall rvm then install ruby using rvm.