rails console doesn't load due to libreadline
Asked Answered
C

10

72

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.

Connelly answered 31/8, 2014 at 11:29 Comment(1)
Possible duplicate of Rails Console Not LoadingSalpingectomy
S
79

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

Sententious answered 12/9, 2014 at 13:58 Comment(8)
worked for me too, thanks! although when running brew doctor it tells me to unlink it? I think that is what caused the error to come up in the first place, strange..Stickpin
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!Marris
I've found @califrench's solution to work after finding rails c was broken after upgrading to Sierra.Astra
no idea why this suddenly started happening this morning but califrench's solution worked for me when none of the others did.... thanks!Goodnight
Didn't work for me... Thanks @califrench, your solution was more simple and it works :DAleda
Thanks @califrench. This worked for me too like most others. I am adding this as community wiki answer. You are still welcome to add this as your own answer, when you get time.Dressler
Thanks @califrench, OP's answer didn't work for me, the comment did. Might want to post it as an answer :)Jaehne
and run rails console after spring stopIlluse
W
77

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!

Woebegone answered 31/8, 2014 at 11:29 Comment(5)
Thanks for posting my solution. I have gotten good feedback and was about to post it. I up-voted this!Marris
@califrench, it's a community wiki, please do some edit to make it as you like and then you will be added as a contributor too. (It's kinda injustice not to see your name here!)Dressler
Solved my issue as well! I'm using Rails v4.2.4. Thanks!Lowbrow
Thanks Califrench and Tareq! I up voted this answer and downvoted the answers that are showing up higher in the rankings (but not as helpful). Unfortunately, I don't have enough rep to change the public totals. Hoping future readers will also place similar votes.Southernmost
Thanks, this worked! In my case, just needed to change ...libreadline.6.dylib to ...libreadline.7.dylibGuillemette
D
52

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.

Debenture answered 1/10, 2016 at 22:4 Comment(6)
Thanks — that fixed it. For rbenv users, the rbenv equivalent is rbenv install -f 2.3.1.Arleyne
Same here! re-installing 2.3.1 fixed it for me.Gel
I do not meet the issue when working in terminal, but only in RubyMine (???). And re-installing fixed it (???).Ellinger
I've seen situations where RubyMine SDK points to an out of date/wrong RVM gemset. Most typically when I upgrade the global default Ruby version. I'd suggest checking the SDKDebenture
Was having issues running knife commands for ChefDK and this fixed it.Hafer
Worked for me, Ruby 2.3.0, Rails 4.2.7, RubyMine 2017.3.1. Thanks!Omission
M
17

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!

Marris answered 2/1, 2017 at 21:22 Comment(0)
C
16

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

Cecilycecity answered 29/12, 2016 at 20:18 Comment(0)
C
9

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.

Centrepiece answered 12/3, 2017 at 16:16 Comment(0)
S
6

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

Sensorium answered 17/2, 2017 at 9:30 Comment(0)
G
5

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
Grouper answered 1/2, 2019 at 9:3 Comment(1)
this is the answerDhruv
H
2

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/ )

Horlacher answered 30/1, 2018 at 21:20 Comment(0)
J
2

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].

Jellaba answered 9/8, 2019 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.