I'm working on a Mac, Sierra 10.12.3, and I'm trying to access a PostgreSQL database via the psql command, but it threw the error

dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/bin/psql
Reason: image not found
Abort trap: 6

A day or two ago, I was working with someone and I needed to install pip, so I ran brew install pip, and it was all good. This is the first time I'm trying to run psql since then and I'm not certain that this has anything to do with my problem, but it seems likely since I haven't made any other changes.

Now I did a little detective work and found that if I went to /usr/local/opt/ there was indeed a readline alias directory that pointed to /usr/local/Cellar/readline/7.0.1 (version 7.0.1 also seeming to have gotten installed at some point - maybe as part of pip? Maybe I did it by mistake...) so it made some sense that the original error should be thrown. I changed the alias to point to /usr/local/Cellar/readline/6.3.8 and the error changed slightly:

dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/bin/psql
Reason: no suitable image found.  Did find:
/usr/local/opt/readline/lib/libreadline.6.dylib: stat() failed with errno=20
Abort trap: 6

So it seems like I'm getting somewhere, but still having an issue. If anyone can shed some light on a solution, I would be forever grateful.


I was able to resolve this by simply running brew switch readline 6.3.8

  • 1
    Hmm, readline is already on v8.0.0 – jersey bean Jun 28 '19 at 23:56
  • Works for me ... slightly altered: Error: readline does not have a version "6.3.8" in the Cellar. readline installed versions: 6.2.4, 7.0.5, 8.0.1 ➜ brew switch readline 6.2.4 – dr. rAI Jan 26 '20 at 1:09

Running brew upgrade gawk worked for me, as suggested by @wisbucky

And that fixed the below error, upon opening a new terminal :

dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
  Referenced from: /usr/local/bin/awk

OS details: macOS Mojave version 10.14.1 (18B75)


my issue was due to my awk being linked to gawk

brew unlink gawk

  • 2
    While that works, you will be removing the symlinks to gawk, which means gawk won't work anymore. To keep gawk, upgrade it with brew upgrade gawk. That will also update the readline version since it's a dependency. Or if you don't want gawk, then brew uninstall gawk. – wisbucky Apr 30 '19 at 18:36

Add a symlink

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

so the message in my case was.

Library not loaded: /usr/local/opt/readline/lib/libreadline.8.0.4

and based on @skwidbreth's answer, I was able to figure out that I had 8.0.4 already installed, I just needed to switch to it:

brew switch readline 8.0.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.