PostgreSQL command psql not found, trouble adding to $PATH

早过忘川 提交于 2020-01-04 01:50:16

问题


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'.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/22701114/postgresql-command-psql-not-found-trouble-adding-to-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!