bash psql:找不到命令 Mac
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36155219/
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
psql: command not found Mac
提问by user3147424
I installed PostgreSQL via the graphical install on http://www.postgresql.org/download/macosx/
我通过http://www.postgresql.org/download/macosx/上的图形安装安装了 PostgreSQL
I see it in my applications and also have the psql terminal in my applications. I need psql to work in the regular terminal for another bash script I'm running for an app.
我在我的应用程序中看到它,并且在我的应用程序中也有 psql 终端。我需要 psql 在常规终端中为我正在为应用程序运行的另一个 bash 脚本工作。
For some reason, when I run
出于某种原因,当我跑步时
psql
in the Mac terminal, my output is
在 Mac 终端中,我的输出是
-bash: psql: command not found
I ran the following in the terminal:
我在终端中运行了以下内容:
locate psql | grep /bin
and the output was
输出是
/Library/PostgreSQL/9.5/bin/psql
I then edited my ~/.bash_profile and added it to the path like so:
然后我编辑了我的 ~/.bash_profile 并将其添加到路径中,如下所示:
export PATH = /Library/PostgreSQL/9.5/bin/psql:$PATH
The only other thing in ~/.bash_profile is SDK man and it's at the bottom of the script as it says it should be. I've tried setting the bath to just the /Library/PostgreSQL/9.5/bin/ as well. I've restarted my terminal also.
~/.bash_profile 中唯一的另一件事是 SDK man,它位于脚本的底部,正如它所说的那样。我也尝试将浴缸设置为 /Library/PostgreSQL/9.5/bin/ 。我也重新启动了我的终端。
How can I get psql to work?
我怎样才能让 psql 工作?
EDITAfter adding to .bashrc, this output is returned when I open terminal
编辑添加到 .bashrc 后,当我打开终端时返回此输出
-bash: export: `/Library/PostgreSQL/9.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin': not a valid identifier
回答by Mark Setchell
You have got the PATH slightly wrong. You need the PATH to "the containing directory", not the actual executable itself.
您的 PATH 略有错误。您需要“包含目录”的 PATH ,而不是实际的可执行文件本身。
Your PATH should be set like this:
你的 PATH 应该这样设置:
export PATH=/Library/PostgreSQL/9.5/bin:$PATH
without the extra sql
part in it. Also, you must remove the spaces around the equals sign.
没有多余的sql
部分。此外,您必须删除等号周围的空格。
Keywords: Postgresql, PATH, macOS, OSX, psql
关键词: Postgresql, PATH, macOS, OSX, psql
回答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.
重新启动您的终端,您将在您的路径中找到它。
回答by Davide Carpini
If someone used homebrew with Mojave or later:
如果有人在 Mojave 或更高版本中使用自制软件:
export PATH=/usr/local/opt/[email protected]/bin:$PATH
change version if you need!
如果需要,请更改版本!
回答by amcp
For me this worked:
对我来说这有效:
Downloading the App: https://postgresapp.com/downloads.html
Running commands to configure $PATH - note though that it didn't work for me. https://postgresapp.com/documentation/cli-tools.html
Manually add it to the .bash_profile document:
cd # to get to your home folder open .bash_profile # to open your bash_profile
In your bash profile add:
# Postgres export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin
Save the file. Restart the terminal. Type 'psql'. Done.
运行命令来配置 $PATH - 请注意,它对我不起作用。 https://postgresapp.com/documentation/cli-tools.html
手动将其添加到 .bash_profile 文档中:
cd # to get to your home folder open .bash_profile # to open your bash_profile
在您的 bash 配置文件中添加:
# Postgres export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin
保存文件。重启终端。输入“psql”。完毕。
回答by Vittorius
Mojave, Postgres was installed via
Mojave,Postgres 是通过安装的
brew install https://raw.githubusercontent.com/lembacon/homebrew-core/bede8a46dea462769466f606f86f82511949066f/Formula/[email protected]
How to get psql in your path:
如何在您的路径中获取 psql:
brew link [email protected] --force
回答by Julien Lopez
Modify your PATH
in .bashrc
, not in .bash_profile
:
修改你的PATH
in .bashrc
,而不是 in .bash_profile
:
http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files
http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files
回答by André Luiz Reis
Open the file .bash_profile
in your Home folder. It is a hidden file.
打开.bash_profile
主文件夹中的文件。这是一个隐藏文件。
Add this path below to the end export PATH line in you .bash_profile
file
:/Applications/Postgres.app/Contents/Versions/latest/bin
将此路径添加到您.bash_profile
文件中
的最后导出路径行:/Applications/Postgres.app/Contents/Versions/latest/bin
The symbol :
separates the paths.
符号:
分隔路径。
Example:
例子:
If the file contains:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
如果文件包含:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
it will become:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin
它会变成:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin
How to show hidden files
如何显示隐藏文件
In Terminal, paste the following: defaults write com.apple.finder AppleShowAllFiles YES
在终端中,粘贴以下内容: defaults write com.apple.finder AppleShowAllFiles YES
回答by Utkarsh Sharma
ANSWERED ON OCTOBER 2017
2017 年 10 月答复
run
跑
export PATH=/Library/PostgreSQL/9.5/bin:$PATH
and then restart your terminal.
然后重启你的终端。
回答by Obinna Nnenanya
If Postgres was downloaded and installed, running this should fix the issue:
如果下载并安装了 Postgres,运行它应该可以解决问题:
sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee
/etc/paths.d/postgresapp
Restart the terminal and you'll be able to use psql
command.
重新启动终端,您将能够使用psql
命令。
回答by mt_
As a postgreSQL newbie I found the os x setup instructions on the postgresql site impenetrable. I got all kinds of errors. Fortunately the uninstaller worked fine.
作为 postgreSQL 新手,我发现 postgresql 站点上的 os x 设置说明难以理解。我遇到了各种各样的错误。幸运的是,卸载程序运行良好。
cd /Library/PostgreSQL/11; open uninstall-postgresql.app/
Then I started over with a brew install followed by this article How to setup PostgreSQL on MacOS
然后我从 brew install 开始,然后是这篇文章如何在 MacOS 上设置 PostgreSQL
It works fine now.
它现在工作正常。