39

I am getting the following error:

$script/console
Loading development environment (Rails 2.2.2)
/opt/ruby-enterprise-1.8.6-20080709/lib/ruby/1.8/irb/completion.rb:10:in `require': no such file to load -- readline (LoadError)

Where can i get the file and what directory should it go in?

Thanks!

Stéphan Kochen
  • 19,513
  • 9
  • 61
  • 50
Jay
  • 6,206
  • 11
  • 48
  • 82

6 Answers6

46

The readline module is normally part of the Ruby package itself.

Did you manually build your Ruby install? If so, you want to make sure libreadline and its headers are installed, and build again.

On Debian/Ubuntu:

apt-get install libreadline-dev

Or on RHEL/CentOS, try

yum install readline-devel

Update:

You are using a very old release of Ubuntu. If you want to keep using it, open /etc/apt/sources.list in a text editor, and change all occurrences of archive.ubuntu.com to old-releases.ubuntu.com. Then, run apt-get update and try the above again.

I urge you to consider updating your installation, though. Ubuntu 7.10 hasn't seen security updates in quite a while, and using it in production is not recommended. Even if it's not a production machine, there's a good chance you'll run into further problems because of old versions of certain libraries/dependencies.

Stéphan Kochen
  • 19,513
  • 9
  • 61
  • 50
  • on "apt-get install libreadline-dev" get the following error: Err http://archive.ubuntu.com gutsy/main libncurses5-dev 5.6+20070716-1ubuntu3 404 Not Found [IP: 91.189.88.45 80] Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/n/ncurses/libncurses5-dev_5.6+20070716-1ubuntu3_amd64.deb 404 Not Found [IP: 91.189.88.45 80] – Jay Dec 08 '10 at 08:55
  • @Shteef i am using CentOS release 5.6 and had sample problem.So I have tried yum install readline-devel as root.but still i am getting same problem.do you have any idea friend? and Ruby path is /usr/local/bin/ruby – Soundar Rathinasamy Oct 28 '11 at 11:09
  • 1
    If it's in `/usr/local`, I guess you built it manually? After installing readline-devel, you need to build ruby again. – Stéphan Kochen Oct 28 '11 at 16:33
31

You need to install the ncurses and readline libraries.

On Ubunutu you could do

sudo apt-get install libreadline5-dev libncurses5-dev

and then you will have to recompile readline which comes with your ruby source

cd <ruby-src-dir>/ext/readline
ruby extconf.rb
make
sudo make install

If you are using RVM you could simply do

rvm package install readline

EDIT:

On newer RVM versions, this last command is

rvm pkg install readline
Pedro Cori
  • 2,046
  • 2
  • 16
  • 23
jatin
  • 1,379
  • 8
  • 7
  • On "sudo apt-get install libreadline5-dev libncurses5-dev" getting: Err http://archive.ubuntu.com gutsy/main libncurses5-dev 5.6+20070716-1ubuntu3 404 Not Found [IP: 91.189.88.40 80] Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/n/ncurses/libncurses5 -dev_5.6+20070716-1ubuntu3_amd64.deb 404 Not Found [IP: 91.189.88.40 80] E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing? – Jay Dec 08 '10 at 14:42
  • Exemplary answer: concise, clear, and covers several different set-ups. I think this should be set as the answer to this question! – Jon Cairns Oct 21 '12 at 08:25
10

Add the following line to your Gemfile and run bundle update

gem 'rb-readline'

credits to similar question/answer at install ruby 1.9.3 using rvm on ubuntu

boulder_ruby
  • 38,457
  • 9
  • 79
  • 100
  • This worked for me as well with a little adjustment: when using rails 4, in the Gemfile set `gem 'rb-readline', '~> 0.4.2'` – Clergyman Dec 19 '13 at 15:30
6

This easiest way to get relief from this problem, just add to your Gemfile:

gem 'rb-readline'

And then run bundle install

Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
Rubyrider
  • 3,567
  • 1
  • 28
  • 34
2

Run the command

rvm requirements

It shows the requirements and dependencies. Install those and reinstall the ruby on rvm

rvm remove 1.9.2
rvm install 1.9.2

It works!

EDIT

If you can't find the requirements option update your rvm.

rvm update --head  # older rvm

or use rvm upgrade

Sayuj
  • 7,464
  • 13
  • 59
  • 76
  • Thanks, Sayuj. I tried the command and got "ERROR: Unrecognized command line argument: 'requirements' ( see: 'rvm usage' )". I ran 'rvm usage' and did not see requirements anywhere in the result. Thanks for trying though. – Jay Jan 11 '12 at 15:52
  • @Jay: Try `rvm -h`. You should get `requirements - Shows additional OS specific dependencies/requirementes for building various rubies.` – Sayuj Jan 11 '12 at 20:24
  • what is the result of `rvm -v` – Sayuj Jan 11 '12 at 20:25
  • @Jay: You may be using old rvm. Try reinstall rvm. https://rvm.beginrescueend.com/ – Sayuj Jan 11 '12 at 20:28
-1

Maybe this is a bullshit answer, but I ran into this problem today after upgrading postgres from 9.5.3 to 9.6, along with which homebrew upgraded readline from 6.something to 7. I ended up rolling back my postgres to 9.5.3 and that resolved the issue.

Darth Egregious
  • 18,184
  • 3
  • 32
  • 54