23

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.

skwidbreth
  • 7,888
  • 11
  • 58
  • 105

3 Answers3

28

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

skwidbreth
  • 7,888
  • 11
  • 58
  • 105
  • 1
    I was getting the same error in a different context, trying to run `bash` commands via `subprocess.Popen()`, and `brew switch readline 6.3.8` worked for that as well. – jalanb Mar 05 '17 at 21:39
  • 1
    That's awesome! Glad this helped - I was really frustrated. – skwidbreth Mar 06 '17 at 22:16
  • 3
    Recently updated hombrew says: `Error: readline does not have a version "6.3.8" in the Cellar. Versions available: 7.0.1, 7.0.3, 7.0.3_1`. _sigh_ – dbenton Jan 16 '18 at 04:26
  • 3
    I don't know if this is a good idea, but I was able to get psql working with a symlink: `ln -s /usr/local/opt/readline/lib/libreadline.7.dylib /usr/local/opt/readline/lib/libreadline.6.dylib` – dbenton Jan 16 '18 at 04:27
  • 2
    This fixed helped me, thanks! But we need to be aware that previous registered brew readline version (in my case 7.0.5) was installed for some reasons before. After switch it is possible that some programs/libs which required previously installed version (in my case 7.0.5) will start to complain and stop working. If this is the case I would recommend doing fix like @dbenton suggested - to have both readline versions registered. – Robert Lujo Sep 24 '18 at 10:10
  • Thanks for helping to keep this advice up to date, @RobertLujo – skwidbreth Sep 24 '18 at 15:01
  • The previous version no longer existed on my machine. In the end I had to reinstall postgres. – pymarco Feb 13 '19 at 19:07
12

Readline has been upgraded but you are still using an older psql from postgres. Upgrading postgres to a current version that uses the current readline fixed the problem for me:

brew upgrade postgres

flurdy
  • 3,782
  • 29
  • 31
  • 1
    This worked for me and seems like a much better solution than symlinking to fool it into using a newer version +1 – Chris Wininger Jul 16 '19 at 13:17
  • 3
    In a realistic scenario, a postgres upgrade can cause for more issues than what is being trying to be solved. This should be recommended only with a sound warning – Raj Oct 08 '19 at 10:22
  • This worked for me. switch readline 6.3.8 didn't. `brew switch readline 6.3.8` `Error: readline does not have a version "6.3.8" in the Cellar.` `readline installed versions: 8.0.1` – ChainLooper Dec 13 '19 at 08:58
  • You can't switch to a version you don't already have installed. – Bricky Jan 09 '20 at 21:50
  • You can, but it is messy. You have to unlink it, find the formula in Homebrew's repo and the exact commit you want to revert to. Similar to what they do here for another formula: https://github.com/helm/helm/issues/4547#issuecomment-423312200 – flurdy Jan 11 '20 at 18:44
11

After I run brew upgrade, I also had this problem.

First, You need to confirm the version of the readline on your Mac.

In your situation, your old readline's version is 6.x. After upgrading, your readline was updated into 7.0.1. So you need to link your new readline.

These code might be helpful.

$ cd /usr/local/opt/readline/lib/  # cd to readline library
$ sudo ln -s libreadline.7.dylib libreadline.6.dylib  # change the link

I think the better way is to change the system readline link, but I don't know how to change.

Marcel Qiu
  • 119
  • 1
  • 3
  • 3
    Another day, another version. To get it to work, I had to `ln -s libreadline.7.dylib libreadline.8.0.dylib` This seems amazingly hacky. The most surprising thing is that it works. – dland Mar 11 '19 at 14:42
  • 5
    @dland Thanks for this hacky fix. Worked for me. Though, I had to change the link parameters: `ln -s libreadline.8.0.dylib libreadline.7.dylib`. – MrLeeh Apr 16 '19 at 07:40
  • If you have version 8 to 8.8 `ls -s libreadline.8.dylib libreadline.8.1.dylib` – Mark Locklear Mar 24 '21 at 13:56