I have installed postgresql on my mac!
However when I run the command "psql" it says:
zsh: command not found: psql
I have located the location of my psql command (with other all postgres commands + pgadmin) and it is in /Users/Library/PostgreSQL/13/bin
when I do echo $PATH I get:
/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Now what do I do to run psql without any error?
/Users/Library/PostgreSQL/13/bin is not in your "path"
Easy solution would be to create a symbolic link for psql in /usr/local/bin/:
ln -s /Users/Library/PostgreSQL/13/bin/psql /usr/local/bin/psql
Otherwise you can edit your profile file and extend your path to /Users/Library/PostgreSQL/13/bin
I also had the same issue and a simple solution is to restart the terminal.
It gives an opportunity for terminal to reload Postgres.
What i did to make it work:
I didn't have a .zshrc file and created one (peeped here link)
Steps for creation:
Open Terminal
Type touch ~/.zshrc to create the respective file. (touch command will create the .zshrc in your current directory but it will be hidden)
Hit Return
To view/open ~/.zshrc you can do either of two things:
Open Finder > Press Cmd+Shift+. (and you will see hidden files) my path to the file: Macintosh HD > Users > anatolii => .zshrc
Or:
Open Terminal > and type: open ~/.zshrc
Editing .zshrc
Open .zshrc in editor and pasted this line:
export PATH=/Library/PostgreSQL/15/bin:$PATH
Related
I have installed postgres in Mac using command
brew install postgresql#9.6
and is successfully installed
brew services start postgresql#9.6 is successful also
==> Successfully started postgresql#9.6 (label: homebrew.mxcl.postgresql#9.6)
But when I tried to access Postgres from my Mac terminal psql postgresql#9.6 it prompt me weird error
-bash: /usr/local/bin/psql: No such file or directory
Am I doing something wrong, how to open psql from my terminal
Why there is no psql file in my /usr/local/bin
The accepted answer is incorrect.
If you install postgresql#9.6 via Homebrew, the right path for the /bin folder is:
/usr/local/Cellar/postgresql#9.6/9.6.15/bin
To connect, just type: psql postgres
If you're curious about the connections details, just type \conninfo and check it.
You must to enabling Postgres command line tools.
If you are using the default terminal, you are going to want to modify the file at
~/.bash_profile
. If you are using something like Oh My Zsh you are going to want to modify the file ~/.zshrc.
To edit this file you likely need to open it via the terminal, so open your terminal and type open ~/.bash_profile. You can replace the word open with subl or whatever text editor you prefer.
Once your zbash_profile or .zshrc file is open, add the following line to the end of the file:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
After that you will need to quit and restart your terminal This is to make sure it reloads with the changes you just made.
Once you have restarted your terminal, try running psql.
psql -U postgres
You should get the following output.
psql (9.6.0)
Type "help" for help.
postgres=#
You can read more on https://www.calhoun.io/how-to-install-postgresql-9-6-on-mac-os-x/
I want to open my .bashrc file and and add a new PATH PHP VERSION export PATH=/opt/plesk/php/7.1/bin:$PATH;
In my root ssh connection i made : ls -a and i saw .bashrc ! but how i could open the file and add my new path ?
Sorry i'm really not a king in terms of command lines
Thanks a lot in advance if someone could help
To open file in editor you can use the following command:
vi ~/.bashrc
Or you can just add the line without opening file in editor:
echo "export PATH=/opt/plesk/php/7.1/bin:$PATH;" >> ~/.bashrc
After editing the file, run the following command (it will apply changes):
source ~/.bashrc
Also, make sure that a ~/.profile is there (sometimes it's missing). Otherwise, create it like this:
echo '[[ -f ~/.bashrc ]] && source ~/.bashrc' > ~/.profile
To start my Postgres server I need to run these commands:
pg_ctl -D /usr/local/var/postgres start
export PGDATA='/usr/local/var/postgres'
Isn't there a way to define the PGDATA permanently and from there on only use commands like pg_ctl start to operate in the shell? Thanks.
You're half way there. The only thing you might want to do is to get PGDATA whenever you open the terminal by adding the export line to your shell config file. On my macOS machine i added the following line:
export PGDATA='/Users/john/.postgres' to ~/.bash_profile file. Don't forget to source it if you want to see the effect immediately by executing . ~/.bash_profile command. That's it from now on you can start your posters server by simply typing pg_ctl start. Hope it was worth the wait for the answer. :)
export will set the context for your current session. So we need to hack our terminal so that we will export this PGDATA env variable to every session.
If you are using zsh, you can simply execute the below command.
echo "export PGDATA='/usr/local/var/postgres'" >> ~/.zshrc
In case you are not using zsh replace ~/.zshrc in the above command with ~/.bashrc or ~/.profile
then, do source ~/.zshrc to see the immediate effect. You can instantly check using echo $PGDATA command.
Whenever you open a new terminal, your environment variable will be available by default.
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'.
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.
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.
I am having trouble accessing Coda from command-line. I installed the "command-line coda" plug-in, verified that my installation is in the correct location, yet I still can seem to access Coda. Coda sits in my "Applications" folder which is the default location for the plug-in.
Anyone have have this problem? Any tips? On the their site it is recommended that you change the path.
export CODEPATH=/Applications/Coda.app
So I included the above line in my .bash_profile which did not help.
$ Coda -v
-bash: Coda: command not found
Thanks for any direction you can provide.
The default way to open an application on a Mac is to use open -a AppName so you should be able to change your bash profile to use that:
$ open -a Coda
I've created a bash script (as opposed to using the plugin) that Gregory Tomlinson originally posted about (it looks like he's since taken it down but it looks like the following).
Create a new file in /bin called coda:
$ cd /bin
$ sudo touch coda
$ vim coda
Hit an i to enter insert mode. Then include the following code:
#! /bin/bash
if [ "$1" = "" ]; then
echo "Please specify a file to open or create"
exit 0
else
for ARG in $*
do
touch -a $ARG && open -a Coda $ARG
done
exit 0
fi
Save and quit (hit the esc to exit insert mode then type :w !sudo tee % >/dev/null followed by the return key, press L for load when prompted, then type :q to quit). Then give that file execute permissions:
$ chmod u+x coda
Start a new Terminal window and you should be able to use:
$ coda filename.foo
Or just:
$ coda
For some strange reason, my paid registered Coda 2 app just wouldn't open for me this morning. I found this terminal command that worked for me:
open -a Coda\ 2
You can also put the following in your ~/.bash_profile file:
alias coda='open -a "Coda 2"'
I had a similar problem. After installing the plug-in, I still couldn't launch coda from the command line. I took a closer look at /user/local/bin and somehow the permissions had gotten reset so I didn't have execute permissions for /user/local/bin.
I updated my permissions with:
sudo chmod o=rx,g=rx /usr/local/bin
This solved my problem. However, Coda won't launch if the specified file does not exist, which makes it hard to create a file from the command line.