Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

brew install postgresql (upgrade) error, could not link - dead links to old non-existent version

Warning: Do not start deleting files manually in Terminal unless you've tried everything else first. Manual deletion may caused uninstall and install programs to crash.

This is QA style post, sharing my path to resolve the issue. I'm sure there are better ways

I picked up an older mac air and wanted to set it up for Ruby and Rails training. During the upgrade I had issues with installing postgresql:

โžœ  ~  brew install postgresql
....
==> Installing postgresql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/postgresql-9.3.5.mountain_lion.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgresql-9.3.5.mountain_lion.bottle.tar.gz
==> Pouring postgresql-9.3.5.mountain_lion.bottle.tar.gz
==> Caveats
...
To reload postgresql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
No such file or directory - /usr/local/Cellar/postgresql/9.2.3/include/server
Error: No such file or directory - /usr/local/Cellar/postgresql/9.2.3/include/server

I'm installing postgresql 9.3.5, I couldn't care less about 9.2.3 not being found!

โžœ  ~  brew install postgresql
Warning: postgresql-9.3.5 already installed, it's just not linked

but postgres was still broken.

What's the problem?

like image 1000
oma Avatar asked Aug 01 '14 08:08

oma


2 Answers

I had the similar problem but with another package. Turned out there had been a bunch of dead links pointing to the old version all other my file system. Here is what helped in my case:

  1. Run brew link <appname> (e.g. brew link postgress);
  2. If completed successfully then you are golden, otherwise proceed with the next step;
  3. Take a look at the path in the error message (e.g. /usr/local/Cellar/postgresql/9.2.3/include/server) transform the path by removing the Cellar/<app name>/<version> from it (e.g. /usr/local/include/server)
  4. Find under that path all links referring to Cellar/<app name>/<version> and remove them;
  5. Goto step 1.

Hope that helps

like image 134
Maxim Vladimirsky Avatar answered Oct 27 '22 18:10

Maxim Vladimirsky


brew update 
brew doctor

is always first steps.

to help finding files, update the files db

sudo /usr/libexec/locate.updatedb

this is similar to updatedb on ubuntu and you might want to alias it.

then you may perform

locate postgresql

and learn more about where things are.

Chances are you made the mistake of deleting the files and folders just like me (sorry, that's a stupid thing to do). What I learn is that then I have a bunch of dead symlinks.

homebrew mostly use /usr/, more specifically /usr/local/bin and puts all source on /usr/local/Cellar, symlink local/bin to Cellar bin

what I did was to hunt down those dead symlinks and kill them over again. unlink.

move into the /usr/local/bin and others in the /usr and do

sudo find . -type l -exec test ! -e {} \; -delete

this test that the target of symlinks exists and delete if not.

To find symlinks in a folder and subfolders do

sudo ls -lR /usr | grep \^l
# and only those pointing to something postgresql:
sudo ls -lR /usr | grep \^l | grep postgresql

that'll get you a step further.

I couldn't even install wget, brew install wgetยด because of somewgetrcissue. I found that being a dead symlink/usr/local/etc/wgetrc`

Having cleaned up the symlinks, my system works much better and finally postgresql installed as a charm

โžœ brew uninstall postgresql
โžœ brew install postgresql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/postgresql-9.3.5.mountain_lion.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/postgresql-9.3.5.mountain_lion.bottle.tar.gz
==> Pouring postgresql-9.3.5.mountain_lion.bottle.tar.gz
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/issue/2510

To migrate existing data from a previous major version (pre-9.3) of PostgreSQL, see:
  http://www.postgresql.org/docs/9.3/static/upgrading.html

When installing the postgres gem, including ARCHFLAGS is recommended:
  ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

To reload postgresql after an upgrade:
    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
==> /usr/local/Cellar/postgresql/9.3.5/bin/initdb /usr/local/var/postgres
==> Summary
๐Ÿบ  /usr/local/Cellar/postgresql/9.3.5: 2927 files, 39M

# and in my project
โžœ bundle
โžœ rake db:create
โžœ rake db:migrate
# YEAH!
like image 34
oma Avatar answered Oct 27 '22 19:10

oma