73

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.

WebQube
  • 8,510
  • 12
  • 51
  • 93
  • Possible duplicate of [Rails Console Not Loading](http://stackoverflow.com/questions/12591585/rails-console-not-loading) – mpoisot Nov 03 '16 at 13:46

10 Answers10

80

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

mauro_oto
  • 1,368
  • 17
  • 23
  • 1
    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.. – ggrillone Dec 03 '14 at 21:56
  • 161
    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! – califrench Oct 10 '16 at 05:36
  • 5
    I've found @califrench's solution to work after finding `rails c` was broken after upgrading to Sierra. – Doug Thompson Oct 16 '16 at 16:02
  • no idea why this suddenly started happening this morning but califrench's solution worked for me when none of the others did.... thanks! – Allen Maxwell Oct 23 '16 at 19:03
  • Didn't work for me... Thanks @califrench, your solution was more simple and it works :D – Leo Gasparrini Dec 15 '16 at 21:30
  • 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. – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Jan 02 '17 at 14:27
  • 1
    Thanks @califrench, OP's answer didn't work for me, the comment did. Might want to post it as an answer :) – Ganesh Hegde Mar 12 '17 at 11:04
  • and run `rails console` after `spring stop` – ogelacinyc Dec 02 '19 at 09:16
78

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!

califrench
  • 429
  • 6
  • 13
  • 3
    Thanks for posting my solution. I have gotten good feedback and was about to post it. I up-voted this! – califrench Mar 13 '17 at 00:05
  • @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!) – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Apr 01 '17 at 10:30
  • Solved my issue as well! I'm using Rails v4.2.4. Thanks! – Abundnce10 May 23 '17 at 17:02
  • 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. – JDenman6 May 28 '18 at 11:32
  • 5
    Thanks, this worked! In my case, just needed to change `...libreadline.6.dylib` to `...libreadline.7.dylib` – Ryan Rebo Feb 09 '19 at 00:15
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.

paws
  • 1,263
  • 15
  • 23
  • 14
    Thanks — that fixed it. For rbenv users, the rbenv equivalent is `rbenv install -f 2.3.1`. – John Y Oct 08 '16 at 10:53
  • 1
    Same here! re-installing 2.3.1 fixed it for me. – cabgfx Nov 14 '16 at 11:36
  • I do not meet the issue when working in terminal, but only in [RubyMine](https://www.jetbrains.com/help/ruby/2016.3/running-rails-console.html) (???). And re-installing fixed it (???). – Franklin Yu Dec 15 '16 at 09:08
  • 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 SDK – paws Dec 15 '16 at 19:09
  • Was having issues running knife commands for ChefDK and this fixed it. – WhyAyala Jan 23 '17 at 21:00
  • Worked for me, Ruby 2.3.0, Rails 4.2.7, RubyMine 2017.3.1. Thanks! – guero64 Jan 27 '18 at 17:25
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!

califrench
  • 429
  • 6
  • 13
16

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

Meekohi
  • 10,390
  • 6
  • 49
  • 58
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.

theterminalguy
  • 1,842
  • 18
  • 20
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

张艳军
  • 241
  • 4
  • 5
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
Santosh Mohanty
  • 468
  • 1
  • 6
  • 23
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/ )

BF4
  • 1,076
  • 7
  • 23
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].