5

I downloaded and installed PostgreSQL and PostGIS from KyngChaos for my OS X 10.10 install. When I run psql I get,

bash: psql: command not found

According to the site How to run psql on Mac OS X? it gets installed into /Library/PostgreSQL. There is no file there.

Evan Carroll
  • 63,051
  • 46
  • 242
  • 479
four-eyes
  • 177
  • 1
  • 1
  • 9
  • I've deleted irelevant and incorrect information, if locate didn't work your locatedb was out of date. and PostGIS has nothing to do with the PATH or PostgreSQL. Also, in the future, use brew. =) – Evan Carroll Dec 07 '17 at 23:20

5 Answers5

7

According to the README included in the dmg file, postgres binaries are installed in /usr/local/pgsql/bin/. You should add these lines in your ~/.bashrc :

export PSQL_DIR=/usr/local/pgsql/bin/
export PATH="$PSQL_DIR:$PATH"

Update your environment with source ~/.bashrc or run a new shell and psql should be available.

Evan Carroll
  • 63,051
  • 46
  • 242
  • 479
Eric Ly
  • 1,212
  • 12
  • 20
  • Would that be the command for a mac as well? – four-eyes Apr 15 '15 at 09:55
  • For sure, i'm using these on my Mac (; – Eric Ly Apr 15 '15 at 09:56
  • Thanks. That worked like a charme. Another questions. It seems that I have to do the export ... every time I restart my computer. Is there a way to do it permanently? – four-eyes Apr 16 '15 at 14:21
  • Create a new file in your home directory named .bashrc and add these lines in this files. Your terminal will then load run these lines each time your open a terminal. – Eric Ly Apr 20 '15 at 12:48
5

It appears your problem is regarding setting Environment Variables correctly. After installation, the command psql won't work because you need to set the correct PATH to this command in your Environment variables file - which will differ a little according to your version.

I just wanted to add a comment here for future inquiries.

I'm working on a MacOS Catalina 10.15.2 and the current default terminal is using a SHELL called 'zsh'.

I used the following command from the terminal:

nano ~/.zshrc

and adding the following line:

export PATH="/Library/PostgreSQL/11/bin:$PATH"

control X (to quit) and S (to Save) and ENTER (previous filename) Please note that this path above will depend on your PostgreSQL version - I would recommend you to look this information on your documentation / website.

0

Mac OS Big Sur:

Before installing zsh, bash was working perfectly fine. After switching from bash to zsh I experienced the infamous: command not found. I realize that my PATH was empty for this particular shell.

in the terminal:

env

then copy the PATH line(s) (could be a multi line value!):

PATH=/....

and in your personnal directory: /Users/your_name/ you should find the .zshrc file. At the end of this file put:

export PATH=/...

quit your terminal, launch it again and you should be good.

0

macOS Monterey && postgres 14

export PSQL_DIR=/Applications/Postgres.app/Contents/Versions/14/bin

export PATH="$PSQL_DIR:$PATH"

  • +1 I had a mentee that had this issue. This was the only place we could find the bin. Thank you for that help. This answer could be improved by including directions on how to add these commands to the .zshrc, .bashrc, and .bash_profiles files so that psql will be persisted. – cody.tv.weber Sep 30 '23 at 18:12
0

I know it's a Windows user habit but the key step is to restart the terminal after executing this command to configure your $PATH to use the included command line tools:

# sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
John K. N.
  • 17,649
  • 12
  • 51
  • 110