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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:13:08  来源:igfitidea点击:

psql: command not found Mac

macosbashpostgresqlpsql

提问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 sqlpart 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:

对我来说这有效:

  1. Downloading the App: https://postgresapp.com/downloads.html

  2. Running commands to configure $PATH - note though that it didn't work for me. https://postgresapp.com/documentation/cli-tools.html

  3. 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.

  1. 下载应用程序:https: //postgresapp.com/downloads.html

  2. 运行命令来配置 $PATH - 请注意,它对我不起作用。 https://postgresapp.com/documentation/cli-tools.html

  3. 手动将其添加到 .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 PATHin .bashrc, not in .bash_profile:

修改你的PATHin .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_profilein your Home folder. It is a hidden file.

打开.bash_profile主文件夹中的文件。这是一个隐藏文件。

Add this path below to the end export PATH line in you .bash_profilefile :/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 psqlcommand.

重新启动终端,您将能够使用psql命令。

Ref: https://postgresapp.com/documentation/cli-tools.html

参考:https: //postgresapp.com/documentation/cli-tools.html

回答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.

它现在工作正常。