为什么我不能将 PostgreSQL 添加到我的路径中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20027374/
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
Why can't I add PostgreSQL to my path?
提问by steven_noble
After I upgraded to Mavericks, PostgreSQL started playing up, giving this error message whenever I call pg_restore
without calling the full path:
在我升级到 Mavericks 后,PostgreSQL 开始播放,每次调用时都会出现此错误消息,pg_restore
而未调用完整路径:
pg_restore: command not found
If I specify the full path it works, but that's obvious not optimal:
如果我指定了它的完整路径,但这显然不是最佳的:
/Applications/Postgres93.app/Contents/MacOS/bin/pg_restore --verbose --clean --no-acl --no-owner -h localhost -U steven -d db/testivate_development $file_path
To fix this problem, I have tried removing all versions of PostgreSQL (with Homebrew) and then installed Postgres.app. You can confirm this has worked like this:
为了解决这个问题,我尝试删除所有版本的 PostgreSQL(使用 Homebrew),然后安装 Postgres.app。您可以确认这是这样工作的:
$ sudo find / -name pg_restore
/Applications/Postgres93.app/Contents/MacOS/bin/pg_restore
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
To add PostgreSQL to my path, I've tried adding each of the following lines to ~/.bash_profile
, ~/bashrc
and ~/.zshrc
, restarting after each attempt:
要将 PostgreSQL 添加到我的路径中,我尝试将以下每一行添加到~/.bash_profile
,~/bashrc
和~/.zshrc
,并在每次尝试后重新启动:
export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
...as per the postgresapp.com documentation, and then...
...根据 postgresapp.com 文档,然后...
export PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"
...as per the comments below.
...根据下面的评论。
None of this has solved my problem.
这些都没有解决我的问题。
回答by l'L'l
Try adding this line to your .bash_profile:
尝试将此行添加到您的 .bash_profile:
export PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"
and remove or comment out the previous reference.
并删除或注释掉先前的引用。
回答by RubyNoob
I had this problem too, so instead of adding this to my path in .bash_profile:
我也有这个问题,所以不要将它添加到我的 .bash_profile 路径中:
export PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"
which is what had been recommended, I added
这是推荐的,我补充说
export PATH="/Applications/Postgres.app/Contents/Versions/9.3/bin:$PATH"
instead. The '9.3' is replaced by your own version.
反而。'9.3' 替换为您自己的版本。
I verified it afterwards using
我后来验证了它使用
which psql
And it found my version, whereas before it reported nothing.
它找到了我的版本,而在它之前什么也没报告。
I then then created a test database with
然后我创建了一个测试数据库
createdb test
This worked like a charm.
这就像一个魅力。
回答by Israel Barba
If you are using zsh, try this line in your .zshrc and then restart the terminal
如果您使用的是 zsh,请在您的 .zshrc 中尝试这一行,然后重新启动终端
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
回答by pndc
The examples others are giving that do export PATH=...
should be the solution to your problem. Since it's not working, you're going to have to debug a problem with your shell that has nothing to do with PostgreSQL.
其他人给出的例子export PATH=...
应该是你问题的解决方案。由于它不起作用,您将不得不调试与 PostgreSQL 无关的 shell 问题。
Firstly, do which pg_restore
to see if there is another file called pg_restore
in your path that is confusing things. which
will usually give no output rather than a helpful error if nothing is found, otherwise it will print the path of what it did found. You may find an old broken install of PostgreSQL in /usr/local/bin
, for example.
首先,which pg_restore
看看pg_restore
你的路径中是否有另一个文件令人困惑。which
如果什么也没找到,通常不会给出任何输出,而不是一个有用的错误,否则它将打印它找到的路径。例如,您可能会在 中找到旧的 PostgreSQL 损坏安装/usr/local/bin
。
If that didn't work, try echo $PATH
from a new shell. Do you see the path to the PostgreSQL binary directory in there? If not, $PATH
is not being set in your shell dot-rc files. This would be the case if you added it to a file called ~/bashrc
since bash(1) actually read ~/.bashrc
. Note the extra dot! I suspect thisis your actual problem.
如果这不起作用,请尝试echo $PATH
使用新外壳。你在那里看到 PostgreSQL 二进制目录的路径了吗?如果没有,$PATH
则是没有在您的 shell dot-rc 文件中设置。如果您将它添加到~/bashrc
自 bash(1) 实际读取~/.bashrc
. 注意额外的点!我怀疑这是你的实际问题。
If that turns out to not be the problem, you can (re)read the rc file into your current session with source ~/.bashrc
. Again, echo $PATH
If it stilldoesn't contain the path, the dot-rc file contains a bug and is not being executed as far as the part that updates $PATH
. You can do bash --verbose ~/.bashrc
to run it, and you'll see each command as it's being executed. The failing command should be the last one displayed. (Note that when you run a script with bash
, it will not set variables in your current shell.)
如果事实证明这不是问题,您可以(重新)将 rc 文件读入当前会话中source ~/.bashrc
。同样,echo $PATH
如果它仍然不包含路径,则 dot-rc 文件包含一个错误并且不会执行到更新的部分$PATH
。你可以bash --verbose ~/.bashrc
运行它,你会看到正在执行的每个命令。失败的命令应该是最后一个显示的命令。(请注意,当您使用 运行脚本时bash
,它不会在您当前的 shell 中设置变量。)
回答by Guillermo Zacur
You need to add the path in your bash_profile
您需要在 bash_profile 中添加路径
nano ~/.bash_profile
纳米 ~/.bash_profile
Add this line (my postgres version is 9.1):
添加这一行(我的 postgres 版本是 9.1):
export PATH=$PATH:/Library/PostgreSQL/9.1/bin/
导出 PATH=$PATH:/Library/PostgreSQL/9.1/bin/
回答by Do Nhu Vy
On macOS Sierra 10.12.1 with PostgreSQL 9.6.0.0
在 macOS Sierra 10.12.1 和 PostgreSQL 9.6.0.0 上
/Applications/Postgres.app/Contents/MacOS/Postgres
Postgres
is binary file.
Postgres
是二进制文件。
回答by user5698801
On my macOS, Postgre 9.6 is installed in
在我的 macOS 上,Postgre 9.6 安装在
/Library/PostgreSQL/9.6
回答by Dmitry Lysenko
on macOS High Sierra 10.13.2 and PostgreSQL 9.6 it works for me:
在 macOS High Sierra 10.13.2 和 PostgreSQL 9.6 上它对我有用:
export PATH=$PATH:/Library/PostgreSQL/9.6/bin:$PATH