87

I cannot execute rails console due to this error:

localhost:TwitterForZombies wiz$ rails c
/Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `require': dlopen(/Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.2.dylib (LoadError)
  Referenced from: /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle
  Reason: image not found - /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin12.2.1/readline.bundle
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `<top (required)>'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:3:in `require'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:38:in `require'
    from /Users/wiz/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:38:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I have installed readline via homebrew. I'd like to keep using rbenv instead of rvm.

Thank you for reading my question.

iHiD
  • 2,450
  • 20
  • 32
wiz
  • 2,887
  • 5
  • 18
  • 18
  • Possible duplicate of [rails console doesn't load due to libreadline](http://stackoverflow.com/questions/25591527/rails-console-doesnt-load-due-to-libreadline) – Santhosh Dec 20 '16 at 09:22

8 Answers8

277

I had the same issue recently with homebrew and libreadline.7.x.dylib / libreadline.6.x.dylib

I solved it by running:

ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib

source: https://github.com/rails/rails/issues/26658

Danh
  • 5,916
  • 7
  • 30
  • 45
Will Clarke
  • 3,480
  • 1
  • 16
  • 13
  • 1
    What a hack :) But it works just fine, for now :D Thanks! – haslo Nov 04 '16 at 11:07
  • 18
    Using symlinks to trick the system into using what is actually a different (major!) version number is generally a bad idea. It would be good if someone more knowledgeable could explain why the above fix is safe. – Pistos Nov 15 '16 at 15:52
  • You're a legend, thank you for this, @wiz should have marked you correct! – Nick Schwaderer Feb 09 '17 at 16:20
  • 1
    A cursory review of the changes between libreadline 6.3 and 7.0 don't show anything that appears to be a breaking change, expect in cases where software may have been relying on undocumented or buggy behavior. I'd be comfortable trying this solution in light of that. – Lyndsy Simon Feb 22 '17 at 16:35
58

Homebrew is great, but once in a while it doesn't play nice with some of the other moving parts.

A brew update && brew upgrade brought in libreadline.7.x.dylib while automatically removing libreadline.6.x.dylib, which ruby was still relying on.

There may be more clever ways to fix the problem, but brute force worked for me:

$ rbenv uninstall 2.3.1
$ rbenv install 2.3.1
$ cd /path/to/my/app
$ bundle

The above assumes the presence of rbenv's ruby-build and, of course, bundler; replace 2.3.1 with whatever version of ruby you are using.

Please note that similar problems can occur with different homebrew-managed libraries (see my own answer to this, for example)

Community
  • 1
  • 1
Giuseppe
  • 5,188
  • 4
  • 40
  • 37
  • Had the same just happen to me — I wonder if there isn't some way for Homebrew to notice that some libs are linked to older versions of some that Homebrew supplies? – slhck Oct 10 '16 at 14:25
  • 2
    This worked for me in El Capitan, with a `gem install bundler` after the rbenv install. – handwovensole Nov 16 '16 at 00:31
  • Will the error occur when I run `brew update && brew upgrade` again? – Frank Fang Dec 20 '16 at 08:41
  • 1
    @FrankFang, it may or may not, and not just for this particular error. Every time a `brew upgrade` replaces ANY older library with a more recent version, there are SOME chances that other programs in your system will complain. – Giuseppe Jan 14 '17 at 10:11
26

I'm on OSX, ruby2.3.0, rails5. Adding gem 'rb-readline' to my Gemfile fixed this problem.

Meekohi
  • 10,390
  • 6
  • 49
  • 58
  • 1
    gem rb-readline worked for me. I added it to the :development, :test group - nice quick fix! – tnum Jan 03 '17 at 20:10
20

As Sachin hinted, installing readline and then reinstalling ruby is the ideal approach - but the details are a bit different for rbenv. Given your file paths, I'm guessing you're on a Mac, so the following should help:

brew install readline ruby-build
env CONFIGURE_OPTS=--with-readline-dir=`brew --prefix readline` rbenv install 1.9.3-p286

This was taken from the ruby-build Wiki and a quick google search.

pat
  • 16,116
  • 5
  • 40
  • 46
  • don't forget to rehash after doing this – Igbanam May 27 '13 at 14:49
  • 2
    After re-installing an existing Ruby version with readline, running a command such as `bundle install` showed me lots of warnings like “Ignoring bcrypt-3.1.11 because its extensions are not built”. As suggested in the answers to [this question](http://apple.stackexchange.com/questions/147939/ruby-on-os-x-10-9-ignoring-gems-because-extensions-are-not-built), `gem pristine --all` fixed all of those errors at once. – Rory O'Kane Oct 11 '16 at 18:50
20

I got the same error with Ruby 2.1.0, and rails 4.0. After searching and trying a lot, finally it work well:) Here are what I did:

rvm cleanup all
rvm autolibs enable
rvm install 2.1.0 

The other ways:

brew update
brew uninstall readline
brew install readline

The autolibs command will force RVM install all dependencies, so you don't need to worry about it.

Hope it's helpful.

Hoa Hoang
  • 1,212
  • 14
  • 20
8

Using mac, El Captain version, it is possible to fix just by doing

rvm reinstall your_ruby_version

(like rvm reinstall ruby-2.3.1)

Hope this helps, good luck!

Danh
  • 5,916
  • 7
  • 30
  • 45
violentr
  • 301
  • 3
  • 6
1

taken from github user @enderahmetyurt (this is the only solution that worked for me).

Solution: Add gem 'rb-readline' to your Gemfile in development group and bundle install.

It's the easiest solution for silly "readline" errors.

whataboutme1
  • 232
  • 1
  • 13
0

try installing readline, and reinstall your ruby

https://rvm.io/packages/readline/

Sachin Singh
  • 7,107
  • 6
  • 40
  • 80
  • thank you for answering, but is there any way to keep using rbenv instead of rvm? – wiz May 26 '13 at 11:43