3

I am trying to add PostgreSQL to my $PATH variable. I tried this to see where psql is

whereis psql

To which I got a null response. I do have the PostgreSQL.app installed so I clicked on "Open psql" from the GUI and it prompted the Terminal to open and display:

 /Applications/Postgres.app/Contents/MacOS/bin/psql; exit;

So I tried to add the above to the $PATH variable in my ~/.bash_profile (which may have its own problems since I don't know if you can add paths with .app extensions to the $PATH) but when I restart my Terminal and do echo $PATH | grep Postgres.app I get nothin'.

Thalatta
  • 4,338
  • 7
  • 42
  • 75

2 Answers2

4

Here's an approach to take help isolate problems you may have.

Step 1: See if you can add PostgreSQL to your PATH without using Bash dot files.

$ export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH;
$ which psql

If this works...

Step 2: Verify that ~\.bash_profile is being sourced when a new user session is started.

Add the following to the end of your ~/.bash_profile:

echo "From bash_profile.";

Now restart Terminal.app or iTerm and see if that message appears about your prompt.

If this works...

Step 3: Add PATH to ~/.bash_profile.

In ~/.bash_profile:

export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH;

Restart your terminal and run:

$ which psql

If you're not seeing:

/Applications/Postgres.app/Contents/MacOS/bin/psql

Then it might be time to scrap trying to install PostgreSQL as a Mac package and use Homebrew.

NOTE: It's psql and NOT pgsql.

franksort
  • 2,953
  • 2
  • 14
  • 23
  • do I need to restart Terminal in between setting the variable and the `whereis` command? Is there a command to reset Terminal that is more legit than just closing and opening Terminal.app? – Thalatta Mar 27 '14 at 23:32
  • No, don't restart the terminal in **Step 1**. After you run the export cmd, what does `echo $PATH;` return? – franksort Mar 27 '14 at 23:33
  • It returns: /Applications/Postgres.app/Contents/Versions/9.3/bin:/Applications/Postgres.app/Contents/Versions/9.3/bin:/Applications/Postgres.app/Contents/MacOS/bin: ... etc. So it adds it to the $PATH – Thalatta Mar 27 '14 at 23:38
  • Ah! So when I write `where is psql` I get the following: `is not found /Applications/Postgres.app/Contents/MacOS/bin/psql` – Thalatta Mar 27 '14 at 23:38
  • I am still getting stuck at **Step 2**. – Thalatta Mar 27 '14 at 23:42
  • Actually you should `which`. Updated my answer. – franksort Mar 27 '14 at 23:43
  • In that case I am stuck at **Step 1** as `which psql` returns a blank line – Thalatta Mar 27 '14 at 23:44
  • 1
    I think it's Homebrew time :). is it just `brew install postgresql` ? – Thalatta Mar 27 '14 at 23:46
  • What happens when you type `/Applications/Postgres.app/Contents/MacOS/bin/psql;`? Does `psql` run? – franksort Mar 27 '14 at 23:48
  • 1
    Wish I could be of more help. The official install docs for Postgres.app are very similar to my answer http://postgresapp.com/documentation/ but I'm stumped. Good luck! – franksort Mar 27 '14 at 23:56
  • 1
    well in anyways the Homebrew approach works beautifully. thank you for all yr help! – Thalatta Mar 28 '14 at 00:02
  • I don't know why I ever even tried a reg mac package instead of just using brew.. Silly me :/ – Alex Boisselle Aug 08 '16 at 19:43
1

From the Postgres documentation page:

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

restart your terminal and you will have it in your path.

mishap
  • 7,133
  • 14
  • 56
  • 89