psql: command not found Mac

后端 未结 11 797
清酒与你
清酒与你 2021-01-29 22:16

I installed PostgreSQL via the graphical install on http://www.postgresql.org/download/macosx/

I see it in my applications and also have the psql terminal in my applicat

相关标签:
11条回答
  • 2021-01-29 22:18

    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.

    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

    It works fine now.

    0 讨论(0)
  • 2021-01-29 22:20

    Open the file .bash_profile in your Home folder. It is a hidden file.

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

    it will become: 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

    0 讨论(0)
  • 2021-01-29 22:20

    If Postgresql was downloaded from official website. After installation, running these commands helped me resolve the psql issue.

    Go to your home directory with cd ~

    In your home directory, run ls -a. Edit the .bash_profile file with vim

    vi .bash_profile opens the vim editor.

    Insert by pressing i on the editor.

    Add export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/<Version Number>/bin

    The Version Number refers to the version number of the postgresql installed on your local machine. In my case, version 12 was installed, so I inputed

    export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/12/bin .

    Press the esc key and press :wq to exit the editor.

    Enter source .bash_profile in your terminal to read and execute the content of a file just passed as an argument in the current shell script.

    Run psql

    terminal result

    In summary:

    • cd ~
    • vi .bash_profile
    • export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/12/bin Take note of the version number
    • exit vim
    • source .bash_profile
    • psql Works
    0 讨论(0)
  • 2021-01-29 22:23

    If Postgres was downloaded and installed, running this should fix the issue:

    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.

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

    0 讨论(0)
  • 2021-01-29 22:28

    Mojave, Postgres was installed via

    brew install https://raw.githubusercontent.com/lembacon/homebrew-core/bede8a46dea462769466f606f86f82511949066f/Formula/postgresql@9.6.rb
    

    How to get psql in your path:

    brew link postgresql@9.6 --force
    
    0 讨论(0)
  • 2021-01-29 22:31

    You have got the PATH slightly wrong. You need the PATH to "the containing directory", not the actual executable itself.

    Your PATH should be set like this:

    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.

    Keywords: Postgresql, PATH, macOS, OSX, psql

    0 讨论(0)
提交回复
热议问题