问题
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