首页 文章

psql:命令找不到Mac

提问于
浏览
33

我在http://www.postgresql.org/download/macosx/上通过图形安装安装了PostgreSQL

我在我的应用程序中看到它,并且在我的应用程序中也有psql终端 . 我需要psql在常规终端中工作另一个bash脚本我正在为一个应用程序运行 .

出于某种原因,当我跑步时

psql

在Mac终端,我的输出是

-bash: psql: command not found

我在终端上运行了以下内容:

locate psql | grep /bin

而输出是

/Library/PostgreSQL/9.5/bin/psql

然后我编辑了〜/ .bash_profile并将其添加到路径中,如下所示:

export PATH = /Library/PostgreSQL/9.5/bin/psql:$PATH

〜/ .bash_profile中唯一的另一件事是SDK man,它位于脚本底部,因为它应该是 . 我已经尝试将浴缸设置为/Library/PostgreSQL/9.5/bin/ . 我也重启了我的终端 .

我怎样才能让psql工作?

EDIT 添加到.bashrc后,当我打开终端时返回此输出

-bash: export: `/Library/PostgreSQL/9.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin': not a valid identifier

5 回答

  • 1

    只是把我的评论作为答案,所以很容易找到...

    你的PATH略有错误 . 您需要PATH到"the containing directory",而不是实际的可执行文件本身 .

    你的PATH应该像这样设置:

    export PATH=/Library/PostgreSQL/9.5/bin:$PATH
    

    没有额外的 sql 部分 . 此外,您必须删除等号周围的空格 .

    Keywords :Postgresql,PATH,macOS,OSX,psql

  • 53

    来自Postgres documentation page:

    sudo mkdir -p /etc/paths.d&& echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp

    重新启动你的终端,你将在你的道路上 .

  • 3

    修改 .bashrc 中的 PATH ,而不是 .bash_profile

    http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

  • 0

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

    将以下路径添加到您 .bash_profile file :/Applications/Postgres.app/Contents/Versions/latest/bin 中的结束导出PATH行

    符号 : 分隔路径 .

    示例:

    如果文件包含: export PATH=/usr/bin:/bin:/usr/sbin:/sbin

    它将成为: export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin

    如何显示隐藏文件

    在终端中,粘贴以下内容: defaults write com.apple.finder AppleShowAllFiles YES

  • 10

    ANSWERED ON OCTOBER 2017

    export PATH=/Library/PostgreSQL/9.5/bin:$PATH
    

    然后重新启动终端 .

相关问题