How to put psql on the path when using Postgres.app on OS X?
Asked Answered
A

11

35

I've installed Postgres93 on my Mac. I can open the application, and "Open psql" through the app which opens up a command line interface with psql.

However, when I type $ which psql nothing is returned. The installation path is /Applications/Postgres93.app. How do I make $ which psql show the correct result?

Mac OS X - Mavericks

PostgreSQL package, I'm not as sure about. I went here and downloaded it - http://postgresapp.com/

Amandine answered 5/1, 2014 at 0:57 Comment(1)
Please always specify (a) your Mac OS X version, since Apple love changing stuff in random and exciting ways, and (b) What PostgreSQL packaging you are using - homebrew, heroku postgres.app, enterprisedb one-click, macports, etc. Easy to guess in this case, but only because you specified the path.Fantasm
F
9

It appears that you installed Heroku's Postgres.app, which is a tool intended for throw-away testing and development. Add the contents of the bundle to your PATH by following the instructions in the Postgres.app documentation - see "command line tools".

Fantasm answered 5/1, 2014 at 1:9 Comment(1)
2020 update: The relevant section in the Postgres.app documentation is now written as "CLI Tools" instead of "command line tools". On the "CLI Tools" page, see "Configure Your $PATH".Stanislaus
G
56

I just had postgres installed and was not able to run the psql command until I ran the following command in my terminal:

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

Now the terminal knows where to find postgres when I use the psql command.

Remember to replace the version number '9.5' with your current version.

Goggin answered 18/2, 2016 at 23:21 Comment(2)
It's recommended to change that 9.5 to latest. There's a nice symlink in the Versions folder.Glidebomb
Thanks! I was not using the "App", but a regular PostreSQL installation, so my directory (and version) was different, but the principle is the same: export PATH="/Library/PostgreSQL/14/bin:$PATH"Prochoras
S
21

I had the same problem with nothing showing for the which psql command till I run the command below to resolve it. The command provided below is just a little tweak of what has already been provided by others here. The only difference is, instead of providing a specific postgres version number in the command, you can simply tell postgres to use the latest postgres version by simply running the following command:

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

And now my terminal was able to find the path to postgres when I run which psql.

Hope this helps.

Supereminent answered 30/4, 2017 at 9:55 Comment(0)
G
14

On macOS Mojave these instructions work well:

  1. If your Postgres has not been installed yet, I suggest you use the great "brew" package manager from here https://brew.sh/ :

    $ brew cask install postgres or you can install it usual way from the website

  2. Put this to the bottom of your ~/.bash_profile file:

    export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:${PATH}"

  3. Restart your terminal or restart your ~/.bash_profile directly with the command:

    $ . ~/.bash_profile

  4. Verify your installation:

    $ psql --version

Granthem answered 24/1, 2019 at 11:42 Comment(0)
R
12

** Edited: to include a permanent fix, not just during your current session. **

I had this same problem, and also found a clear answer lacking in the docs.

To fix:

  1. Download the new app, and follow the instructions to move it to the Applications folder

  2. Add the new bundle to your path by typing the following in your Terminal (version number specific - mine is 9.4): PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

  3. To fix the issue on a permanent basis, run the same line but with export in front: export PATH="/Applications/Postgres.app/Contents/Versions/9.4/bin:$PATH"

Reddin answered 10/4, 2014 at 20:30 Comment(1)
Does this change $PATH permanently? For me it only lasted until I closed the Terminal window. Editing the ~/.bash_profile file was the permanent solution in my case.Iwo
F
9

It appears that you installed Heroku's Postgres.app, which is a tool intended for throw-away testing and development. Add the contents of the bundle to your PATH by following the instructions in the Postgres.app documentation - see "command line tools".

Fantasm answered 5/1, 2014 at 1:9 Comment(1)
2020 update: The relevant section in the Postgres.app documentation is now written as "CLI Tools" instead of "command line tools". On the "CLI Tools" page, see "Configure Your $PATH".Stanislaus
L
6

On macos mojave i've added the following line on my ~/.profile :

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

the psql command line client lies into this folder. i've used the enterprisedb installer.

Lepidolite answered 13/11, 2018 at 4:5 Comment(1)
This worked great for me. "10" referring to the installed PostgreSQL version, which today, if you've installed the latest version, would be "11". Above line would in that case be export PATH=$PATH:/Library/PostgreSQL/11/bin.Coracorabel
E
5

I just experienced the same problem, and solved it by adding export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin to .bash_profile. Note that this line is version-specific, so be sure to check this line against your current version of Postgres.app.

Estellaestelle answered 29/4, 2015 at 2:13 Comment(0)
F
2

Using Mac OS Monterey, the latest Homebrew (3.4.0) and postgres@13.

I was able to add psql to the path by using -

export PATH="/opt/homebrew/Cellar/postgresql@13/13.6/bin:$PATH"

Replace @13 and 13.6 with your version.

The latest homebrew install location seems to be /opt/homebrew/*

Fabriane answered 28/2, 2022 at 22:16 Comment(0)
A
1

I'm using catalina 10.15.3 and I had the same issue after installing psql using homebrew. Then I noticed, homebrew mentioned

==> libpq libpq is keg-only, which means it was not symlinked into /usr/local, because conflicts with postgres formula.

If you need to have libpq first in your PATH run:

echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile

So, I ran 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile and psql was added to my path

Allonge answered 18/4, 2020 at 0:41 Comment(0)
K
0

In Mac, there is a SQL Shell application already under /Applications/PostgresSQL try that

Also, you can run /Library/PostgreSQL/11/scripts/runpsql.sh

Kirkland answered 25/6, 2019 at 0:47 Comment(0)
D
0

In my case, I installed Postgres12 and had the same issue. I had to look out for the location of my bin folder. It happened to be in /Applications/2ndQuadrant/PostgreSQL/12/bin. So I had to run export PATH="/Applications/2ndQuadrant/PostgreSQL/12/bin:$PATH" in my terminal and restart the terminal. That solved it.

Dour answered 26/5, 2020 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.