使用“brew link”在 PostgreSQL 之间切换时遇到问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8766282/
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-20 23:32:07  来源:igfitidea点击:

Having Trouble Using "brew link" to switch between PostgreSQLs

macospostgresqlhomebrew

提问by Ray

I want to run a Rails app on Heroku so I installed PostgreSQL on my Snow Leopard machine using Homebrew. Currently, brew installs 9.1.2 into /usr/local/Cellar/postgresql. After some research, I discovered that the free, shared version of Heroku requires 8.3.x. While homebrew-alt doesn't have 8.3, it does have 8.4 so I downloaded it instead and it installed into /usr/local/Cellar/postgresql8. I then confirmed that I am able to create and run databases on each version. Thinking that I could use "brew [link | unlink] to switch back and forth, I ran "brew unlink postgresql8" and then "brew link postgresql". However, running the latter command results in this error:

我想在 Heroku 上运行 Rails 应用程序,所以我使用 Homebrew 在我的 Snow Leopard 机器上安装了 PostgreSQL。目前,brew 将 9.1.2 安装到 /usr/local/Cellar/postgresql 中。经过一番研究,我发现 Heroku 的免费共享版本需要 8.3.x。虽然 homebrew-alt 没有 8.3,但它有 8.4,所以我下载了它并将它安装到 /usr/local/Cellar/postgresql8 中。然后我确认我能够在每个版本上创建和运行数据库。想到可以用“brew [link | unlink]来回切换,我跑了”brew unlink postgresql8”,然后“brew link postgresql”。但是,运行后一个命令会导致这个错误:

Linking /usr/local/Cellar/postgresql/9.1.2... Error: Cannot link postgresql Another version is already linked: /usr/local/Cellar/postgresql/9.1.2

链接 /usr/local/Cellar/postgresql/9.1.2... 错误:无法链接 postgresql 另一个版本已链接:/usr/local/Cellar/postgresql/9.1.2

Is there any way to do this (switch back and forth) or am I misunderstanding how brew link/unlink is supposed to be used?

有什么办法可以做到这一点(来回切换)还是我误解了 brew link/unlink 应该如何使用?

By the way, "brew list" shows "postgresql" and "postgresql8" so I don't think it's the case that I should say "brew link postgresql9".

顺便说一下,“brew list”显示“postgresql”和“postgresql8”,所以我不认为我应该说“brew link postgresql9”。

Thanks.

谢谢。

回答by mipadi

Use brew switch, which is an extension shipped with Homebrew. In your case, you could use 8.4 by running

使用brew switch,这是 Homebrew 附带的扩展。在您的情况下,您可以通过运行来使用 8.4

$ brew switch postgresql 8.4

回答by Ray

Thanks, mipadi! That did the trick. There was only one additional thing that I needed to do. The 'brew switch' command assumes all versions of postgresql are installed in /usr/local/Cellar/postgresql. That was not the case with version 8.4.8 as it was installed in /usr/local/Cellar/postgresql8. Consequently I had to create a symbolic link to point to this older version:

谢谢,米帕迪!这就是诀窍。我只需要做一件额外的事情。'brew switch' 命令假设所有版本的 postgresql 都安装在/usr/local/Cellar/postgresql. 版本 8.4.8 并非如此,因为它安装在/usr/local/Cellar/postgresql8. 因此,我必须创建一个符号链接来指向这个旧版本:

cd /usr/local/Cellar/postgresql
ln -s ../postgresql8/8.4.8 8.4.8

Naturally, it also makes sense to keep your database clusters in separate directories:

当然,将数据库集群保存在不同的目录中也是有意义的:

/usr/local/var/postgres/8.4.8
/usr/local/var/postgres/9.1.2