rails console doesn't load due to libreadline

Ruby on-RailsRubyMacos

Ruby on-Rails Problem Overview


I have recently reinstalled ruby 2.1.2 like so since I wanted to install a gem (ruby-debug-ide)

sudo rvm reinstall 2.1.2 --disable-binary --with-gcc=gcc-4.2

Since then, I can't load my console using bundle exec rails c due to the following error :

/Users/ohad/.rvm/gems/ruby-2.1.2@aaa/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require': dlopen(/Users/ohad/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/x86_64-darwin13.0/readline.bundle, 9): Library not loaded: @@HOMEBREW_PREFIX@@/opt/readline/lib/libreadline.6.dylib (LoadError)
  Referenced from: /Users/ohad/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/x86_64-darwin13.0/readline.bundle

Tried brew uninstall readline and brew install --build-from-source readline which worked but didn't solve my problem.

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Ran across this today, to solve it I did:

brew rm -f readline

brew install readline

brew link readline --force

Hope it helps.

EDIT: I recently ran into this problem again (after downgrading Ruby) since I wrote this, and I now prefer @califrench's solution from the comments below:

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

Solution 2 - Ruby on-Rails

> Based on a comment on the accepted answer with more up-votes than the answer, this seems to be the most popular solution.

Looks like rails 4.2.6 was looking for libreadline.6 instead of libreadline. So just need to create a symlink.

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

Hope this helps others who are still stuck!

Solution 3 - Ruby on-Rails

I was able to resolve the same problem by reinstalling Ruby. On the Homebrew side reinstalling readline (even from source) didn't help.

I'm using RVM so this sorted it for me:

rvm reinstall 2.3.1

I think Homebrew may have pulled in readline v7 recently for some other package, which I suspect could well be the culprit.

Solution 4 - Ruby on-Rails

After getting a lot of positive feedback on my comment on @mauro_oto's post, I thought I'd post this as an answer:

>For me cp /usr/local/opt/readline/lib/libreadline.dylib /usr/local/opt/readline/lib/libreadline.6.dylib did the trick. Looks like rails 4.2.6 was looking for libreadline.6 instead of libreadline. I probably should have symlinked it to be honest though. So ln -s /usr/local/opt/readline/lib/libreadline.dylib /usr/local/opt/readline/lib/libreadline.6.dylib is more appropriate. hope this helps others who are still stuck!

Solution 5 - Ruby on-Rails

Adding gem 'rb-readline' to my Gemfile fixed this problem for me. See https://github.com/ConnorAtherton/rb-readline.

Solution 6 - Ruby on-Rails

None of all this worked for me. I am using osx sierra. This what worked for me.

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

Hope this helps someone out there.

Solution 7 - Ruby on-Rails

My ENV: Ruby: 2.2.1, Rails: 4.2.1, macOS Sierra 10.12.4;

The below command works for me and my colleague:

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

Solution 8 - Ruby on-Rails

This solved my problem:

Replace libreadline.{version}.dylib with the version you are getting error for:

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

Solution 9 - Ruby on-Rails

On OSX using homebrew, you can specify which readline version is active. e.g.

brew switch readline 6.3.8

(it's likely installed in /usr/local/Cellar/readline/ )

Solution 10 - Ruby on-Rails

I was experiencing a similar problem but with more updated versions. The error I had was:

dlopen(/Users/juanjo/.rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)
  Referenced from: /Users/juanjo/.rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/readline.bundle
  Reason: image not found - /Users/juanjo/.rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/x86_64-darwin18/readline.bundle

The important part is Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib

Looking at /usr/local/opt/readline/lib/ I saw I had installed libreadline.8.dylib, not 7.

To solve my problem, guided by the other answers, I had to do the following:

ln -s /usr/local/opt/readline/lib/libreadline.8.dylib /usr/local/opt/readline/lib/libreadline.7.dylib

In other words: ln -s /.../[libreadline you have] /.../[libreadline you need].

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWebQubeView Question on Stackoverflow
Solution 1 - Ruby on-Railsmauro_otoView Answer on Stackoverflow
Solution 2 - Ruby on-RailsTᴀʀᴇǫ MᴀʜᴍᴏᴏᴅView Answer on Stackoverflow
Solution 3 - Ruby on-RailspawsView Answer on Stackoverflow
Solution 4 - Ruby on-RailscalifrenchView Answer on Stackoverflow
Solution 5 - Ruby on-RailsMeekohiView Answer on Stackoverflow
Solution 6 - Ruby on-RailstheterminalguyView Answer on Stackoverflow
Solution 7 - Ruby on-Rails张艳军View Answer on Stackoverflow
Solution 8 - Ruby on-RailsSantosh MohantyView Answer on Stackoverflow
Solution 9 - Ruby on-RailsBF4View Answer on Stackoverflow
Solution 10 - Ruby on-RailsJuan José RamírezView Answer on Stackoverflow