Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac psql/readline - Library not loaded

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.

like image 623
skwidbreth Avatar asked Feb 20 '17 23:02

skwidbreth


3 Answers

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

like image 88
skwidbreth Avatar answered Nov 06 '22 18:11

skwidbreth


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

like image 26
flurdy Avatar answered Nov 06 '22 18:11

flurdy


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.

like image 11
Marcel Qiu Avatar answered Nov 06 '22 17:11

Marcel Qiu