3

When installing PostgreSQL via Homebrew on Mac (OSX 10.11.6) I get the following errors:

Error: The `brew link` step did not complete successfully The formula
  built, but is not symlinked into /usr/local

and

initdb: file "/usr/local/share/postgresql/postgres.bki" does not exist
  This might mean you have a corrupted installation or identified the 
  wrong directory with the invocation option -L.

The /postgresql folder doesn't exist.

Not sure if it's relevant, but I already have OpenSSL 1.0.2o_2 and Readline 7.0.5 installed via Homebrew.

Does anyone know why this error occurs and how I can solve it?

anothernode
  • 5,100
  • 13
  • 43
  • 62
Robert Samarji
  • 103
  • 1
  • 11
  • Had some trouble also with Postgres installing with Homebrew. Found https://postgresapp.com/ for managing different PostgreSQL versions on OSX – andro83 Aug 01 '18 at 11:31
  • Thanks for the tip, struggling to find a solution to this. Will probably try that instead! – Robert Samarji Aug 01 '18 at 11:39
  • Have you had a look at the output of `brew doctor`? Maybe it could give you a clue. Also, could you show how exactly you install PostgreSQL via Homebrew? – anothernode Aug 01 '18 at 11:49
  • 1
    The directory `/usr/local/share/postgresql` should contain all the symlinks to the relevant files installed by Homebrew after a successful installation. So, I guess, the question is why this directory and the symlinks do not get created in your case. I just did `brew reinstall postgresql` on my machine and it works fine. Did you maybe manually change the permissions of `/usr/local/share`? – anothernode Aug 01 '18 at 11:58
  • Thanks anothernode. You're right, it was a permissions issue. Recursively sudo chowning the /user/local/share folder did the trick. – Robert Samarji Aug 01 '18 at 12:04
  • Postgresql on Mac M2 using brew: https://stackoverflow.com/questions/69754628/psql-error-connection-to-server-on-socket-tmp-s-pgsql-5432-failed-no-such/75885761#75885761 – ugola Mar 31 '23 at 20:12

2 Answers2

12

In my case, I had installed libpq which prevented postgresql from linking. Unlinking libpq followed by linking postgresql fixed the issue for me.

brew unlink libpq
brew link postgresql
brew postinstall postgresql
ChrisM
  • 121
  • 1
  • 3
0

Managed to solve the problem. It's a permissions issue. The original answer can be found here: Homebrew: Could not symlink, /usr/local/bin is not writable

In short, perform the following commands:

sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
sudo chown -R `whoami`:admin /usr/local/opt
Robert Samarji
  • 103
  • 1
  • 11