postgresql 在 OS X 上使用 Postgres.app 时如何将 psql 放在路径上?

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

How to put psql on the path when using Postgres.app on OS X?

macospostgresqlpsql

提问by Don P

I've installed Postgres93 on my Mac. I can open the application, and "Open psql" through the app which opens up a command line interface with psql.

我已经在我的 Mac 上安装了 Postgres93。我可以打开应用程序,并通过应用程序打开 psql 的命令行界面“打开 psql”。

However, when I type $ which psqlnothing is returned. The installation path is /Applications/Postgres93.app. How do I make $ which psqlshow the correct result?

但是,当我输入时$ which psql没有返回任何内容。安装路径为/Applications/Postgres93.app. 如何$ which psql显示正确的结果?

Mac OS X - Mavericks

Mac OS X - 小牛队

PostgreSQL package, I'm not as sure about. I went here and downloaded it - http://postgresapp.com/

PostgreSQL 包,我不太确定。我去这里下载了它 - http://postgresapp.com/

采纳答案by Craig Ringer

It appears that you installed Heroku's Postgres.app, which is a tool intended for throw-away testing and development. Add the contents of the bundle to your PATHby following the instructions in the Postgres.app documentation- see "command line tools".

您似乎安装了 Heroku 的Postgres.app,这是一个用于一次性测试和开发的工具。按照 Postgres.app 文档中的说明将包的内容添加到您PATH文件中- 请参阅“命令行工具”。

回答by Bert

I just had postgresinstalled and was not able to run the psqlcommand until I ran the following command in my terminal:

我刚刚安装了postgres并且无法运行psql命令,直到我在终端中运行以下命令:

export PATH="/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH"

Now the terminal knows where to find postgres when I use the psqlcommand.

现在,当我使用psql命令时,终端知道在哪里可以找到 postgres 。

Remember to replace the version number '9.5' with your current version.

请记住将版本号“9.5”替换为您当前的版本。

回答by Vick Swift

I had the same problem with nothing showing for the which psqlcommand till I run the command below to resolve it. The command provided below is just a little tweak of what has already been provided by others here. The only difference is, instead of providing a specific postgres version number in the command, you can simply tell postgres to use the latest postgres version by simply running the following command:

在我运行下面的命令来解决它之前,我遇到了同样的问题,没有显示 which psql命令。下面提供的命令只是对这里其他人已经提供的内容的一点点调整。唯一的区别是,您无需在命令中提供特定的 postgres 版本号,只需运行以下命令即可告诉 postgres 使用最新的 postgres 版本:

export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

导出路径="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"

And now my terminal was able to find the path to postgres when I run which psql.

现在,当我运行which psql时,我的终端能够找到 postgres 的路径

Hope this helps.

希望这可以帮助。

回答by jennystanchak

** Edited: to include a permanent fix, not just during your current session. **

** 已编辑:包括永久修复,而不仅仅是在您当前的会话期间。**

I had this same problem, and also found a clear answer lacking in the docs.

我遇到了同样的问题,并且还发现文档中缺少明确的答案。

To fix:

修理:

  1. Download the new app, and follow the instructions to move it to the Applications folder

  2. Add the new bundle to your pathby typing the following in your Terminal (version number specific - mine is 9.4): PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

  3. To fix the issue on a permanent basis, run the same line but with export in front: export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

  1. 下载新的应用程序,然后按照说明将其移动到应用程序文件夹

  2. 通过在终端中键入以下内容(特定于版本号 - 我的是 9.4),将新包添加到您的路径中PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

  3. 要永久解决此问题,请运行相同的行,但在前面带有 export: export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

回答by om2c0de

On macOS Mojave these instructions work well:

在 macOS Mojave 上,这些说明运行良好:

  1. Ifyour Postgres has not been installed yet, I suggest you use the great "brew"package manager from here https://brew.sh/:

    $ brew cask install postgresor you can install it usual way from the website

  2. Put this to the bottom of your ~/.bash_profilefile:

    export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:${PATH}"

  3. Restart your terminalor restart your ~/.bash_profiledirectly with the command:

    $ . ~/.bash_profile

  4. Verify your installation:

    $ psql --version

  1. 如果您的 Postgres尚未安装,我建议您使用https://brew.sh/ 中出色的“brew”包管理器:

    $ brew cask install postgres或者您可以从网站上以通常的方式安装它

  2. 把它放在你的~/.bash_profile文件的底部:

    export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:${PATH}"

  3. 重新启动您的终端或直接使用以下命令重新启动您的 ~/.bash_profile

    $ . ~/.bash_profile

  4. 验证您的安装:

    $ psql --version

回答by rainbowsorbet

I just experienced the same problem, and solved it by adding export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/binto .bash_profile. Note that this line is version-specific, so be sure to check this line against your current version of Postgres.app.

我刚刚遇到了同样的问题,并通过添加export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin到 .bash_profile解决了它。请注意,此行是特定于版本的,因此请务必根据您当前的 Postgres.app 版本检查此行。

回答by Sombriks

On macos mojave i've added the following line on my ~/.profile:

在 macos mojave 上,我在~/.profile上添加了以下行:

export PATH=$PATH:/Library/PostgreSQL/10/bin

the psql command line client lies into this folder. i've used the enterprisedb installer.

psql 命令行客户端位于此文件夹中。我使用了Enterprisedb 安装程序

回答by Pintu Mishra

In Mac, there is a SQL Shell application already under /Applications/PostgresSQL try that

在 Mac 中,/Applications/PostgresSQL 下已经有一个 SQL Shell 应用程序试试看

Also, you can run /Library/PostgreSQL/11/scripts/runpsql.sh

此外,您可以运行 /Library/PostgreSQL/11/scripts/runpsql.sh

回答by Suvro Choudhury

I'm using catalina 10.15.3 and I had the same issue after installing psql using homebrew. Then I noticed, homebrew mentioned

我正在使用 catalina 10.15.3,在使用自制软件安装 psql 后我遇到了同样的问题。然后我注意到,提到自制软件

==> libpq libpq is keg-only, which means it was not symlinked into /usr/local, because conflicts with postgres formula.

==> libpq libpq 是 keg-only,这意味着它没有符号链接到 /usr/local,因为与 postgres 公式冲突。

If you need to have libpq first in your PATH run:

如果您需要首先在 PATH 中运行 libpq:

echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile

echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile

So, I ran 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile and psql was added to my path

所以,我运行了 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile 并将 psql 添加到我的路径中

回答by Benito

In my case, I installed Postgres12 and had the same issue. I had to look out for the location of my bin folder. It happened to be in /Applications/2ndQuadrant/PostgreSQL/12/bin. So I had to run export PATH="/Applications/2ndQuadrant/PostgreSQL/12/bin:$PATH"in my terminal and restart the terminal. That solved it.

就我而言,我安装了 Postgres12 并遇到了同样的问题。我必须注意我的 bin 文件夹的位置。它恰好在/Applications/2ndQuadrant/PostgreSQL/12/bin. 所以我不得不export PATH="/Applications/2ndQuadrant/PostgreSQL/12/bin:$PATH"在我的终端中运行并重新启动终端。那解决了它。