为什么我不能将 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

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

Why can't I add PostgreSQL to my path?

macospostgresql

提问by steven_noble

After I upgraded to Mavericks, PostgreSQL started playing up, giving this error message whenever I call pg_restorewithout 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, ~/bashrcand ~/.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_restoreto see if there is another file called pg_restorein your path that is confusing things. whichwill 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 $PATHfrom a new shell. Do you see the path to the PostgreSQL binary directory in there? If not, $PATHis not being set in your shell dot-rc files. This would be the case if you added it to a file called ~/bashrcsince 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 $PATHIf 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 ~/.bashrcto 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

Postgresis 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