brew install postgresql (upgrade) 错误,无法链接 - 死链接到旧的不存在的版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25075888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:33:53  来源:igfitidea点击:

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

macospostgresqlhomebrew

提问by oma

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

这是 QA 风格的帖子,分享我解决问题的途径。我相信有更好的方法

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:

我拿起一台旧的 mac air,想将它设置为 Ruby 和 Rails 培训。在升级过程中,我在安装 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!

我正在安装 postgresql 9.3.5,我不在乎找不到 9.2.3!

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

but postgres was still broken.

但是 postgres 仍然坏了。

What's the problem?

有什么问题?

采纳答案by oma

brew update 
brew doctor

is always first steps.

永远是第一步。

to help finding files, update the files db

为了帮助查找文件,更新文件 db

sudo /usr/libexec/locate.updatedb

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

这类似于 ubuntu 上的 updatedb,您可能希望将其别名化。

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/binand puts all source on /usr/local/Cellar, symlink local/bin to Cellar bin

自制软件主要使用/usr/,更具体地说/usr/local/bin,将所有源代码都放在/usr/local/Cellar,符号链接 local/bin 到 Cellar bin

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

我所做的是寻找那些死的符号链接并再次杀死它们。取消链接。

move into the /usr/local/binand others in the /usrand do

进入/usr/local/bin和其他人在/usr和做

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`

我什至无法安装 wget、brew install wget′ because of somewgetrc issue. 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

清理符号链接后,我的系统运行得更好,最后安装了 postgresql 作为一个魅力

? 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!

回答by Maxim Vladimirsky

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.
  1. 运行brew link <appname>(例如brew link postgress);
  2. 如果成功完成,那么你就是金子,否则继续下一步;
  3. 查看错误消息中的路径(例如/usr/local/Cellar/postgresql/9.2.3/include/server)通过从中删除Cellar/<app name>/<version>来转换路径(例如/ usr/本地/包含/服务器
  4. 在该路径下找到所有指向Cellar/<app name>/<version> 的链接并删除它们;
  5. 转到步骤 1。

Hope that helps

希望有帮助

回答by fronterace

I had the same problem on Yosemite 10.10.3.

我在优胜美地 10.10.3 上遇到了同样的问题。

My steps were:

我的步骤是:

  1. Install latest OS updates
  2. List item
  3. Install updates from xCode
  4. in terminal run command: brew install postgresql
  5. in terminal run command: sudo brew link postgresql
  6. in terminal run command: gem install pg -v '0.18.1'
  1. 安装最新的操作系统更新
  2. 项目清单
  3. 从 xCode 安装更新
  4. 在终端运行命令: brew install postgresql
  5. 在终端运行命令中:sudo brew link postgresql
  6. 在终端运行命令中: gem install pg -v '0.18.1'

then bundle install and it's done.

然后捆绑安装就完成了。

回答by codeAligned

I ran brew doctor and followed the relevant suggestions. In this case

我跑了 brew doctor 并遵循了相关建议。在这种情况下

Warning: The following directories do not exist:/usr/local/include
You should create these directories and change their ownership to your account.
  sudo mkdir -p /usr/local/include
  sudo chown -R $(whoami) /usr/local/include

After that, I was able to run brew link postgresql

之后,我能够运行 brew link postgresql