找不到 PostgreSQL 命令 psql,无法添加到 $PATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22701114/
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
PostgreSQL command psql not found, trouble adding to $PATH
提问by Thalatta
I am trying to add PostgreSQL to my $PATH variable. I tried this to see where psql
is
我正在尝试将 PostgreSQL 添加到我的 $PATH 变量中。我试过这个,看看psql
是
whereis psql
To which I got a null response. I do have the PostgreSQL.app installed so I clicked on "Open psql" from the GUI and it prompted the Terminal to open and display:
我得到了一个空响应。我确实安装了 PostgreSQL.app,所以我从 GUI 中单击“打开 psql”,它提示终端打开并显示:
/Applications/Postgres.app/Contents/MacOS/bin/psql; exit;
So I tried to add the above to the $PATH
variable in my ~/.bash_profile
(which may have its own problems since I don't know if you can add paths with .app extensions to the $PATH) but when I restart my Terminal and do echo $PATH | grep Postgres.app
I get nothin'.
因此,我尝试将上述内容添加到$PATH
我的变量中~/.bash_profile
(这可能有其自身的问题,因为我不知道您是否可以将带有 .app 扩展名的路径添加到 $PATH)但是当我重新启动我的终端时,echo $PATH | grep Postgres.app
我什么也没得到'。
采纳答案by franksort
Here's an approach to take help isolate problems you may have.
这是一种帮助隔离您可能遇到的问题的方法。
Step 1: See if you can add PostgreSQL to your PATH without using Bash dot files.
第 1 步:看看是否可以在不使用 Bash 点文件的情况下将 PostgreSQL 添加到您的 PATH 中。
$ export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH;
$ which psql
If this works...
如果这有效...
Step 2: Verify that ~\.bash_profile
is being sourced when a new user session is started.
第 2 步:~\.bash_profile
在启动新用户会话时验证其来源。
Add the following to the end of your ~/.bash_profile
:
将以下内容添加到您的末尾~/.bash_profile
:
echo "From bash_profile.";
Now restart Terminal.app
or iTerm
and see if that message appears about your prompt.
现在重新启动Terminal.app
或iTerm
查看是否出现有关您的提示的消息。
If this works...
如果这有效...
Step 3: Add PATH to ~/.bash_profile
.
第 3 步:将 PATH 添加到~/.bash_profile
.
In ~/.bash_profile
:
在~/.bash_profile
:
export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH;
Restart your terminal and run:
重新启动终端并运行:
$ which psql
If you're not seeing:
如果您没有看到:
/Applications/Postgres.app/Contents/MacOS/bin/psql
Then it might be time to scrap trying to install PostgreSQL as a Mac package and use Homebrew.
那么可能是时候放弃尝试将 PostgreSQL 安装为 Mac 包并使用 Homebrew 了。
NOTE: It's psql
and NOT pgsql
.
注意:它是psql
而不是pgsql
。
回答by mishap
From the Postgres documentation page:
从 Postgres文档页面:
sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | 须藤三通/etc/paths.d/postgresapp
restart your terminal and you will have it in your path.
重新启动您的终端,您将在您的路径中找到它。