Official page do not mention such case. But many users need only psql without a local database (I have it on AWS). Brew do not have psql.
-
Why do you think there exists a "correct way" to do this, given that you linked to the official download page, which says there isn't a way? – Ssswift Jun 21 '17 at 17:50
-
For those on MacPorts, here's what I did: superuser.com/questions/305031/… – sudo Sep 1 at 20:04
-
@Ssswift It doesn't say there isn't a way, just doesn't say there is a way. – sudo Sep 1 at 20:05
You could also use homebrew to install libpq.
brew install libpq
This would give you psql, pg_dump and a whole bunch of other client utilities without installing Postgres.
You then add the installation directory to your path. In my case, the directory location is:
/usr/local/Cellar/libpq/10.3/bin
-
11Works like a charm after creating symlink: ln -s /usr/local/Cellar/libpq/10.3/bin/psql /usr/local/bin/psql – Engrost Apr 30 '18 at 10:37
-
12You could also do
brew link --force libpqbut that will create a bunch of other symlinks you may not want/need. – Dave Jun 20 '18 at 11:39 -
10
-
1symlinks du jour
ln -s /usr/local/Cellar/libpq/11.3/bin/psql /usr/local/bin/psql/ln -s /usr/local/Cellar/libpq/11.3/bin/pg_dump /usr/local/bin/pg_dump/ln -s /usr/local/Cellar/libpq/11.3/bin/pg_restore /usr/local/bin/pg_restore– hotzen May 15 at 9:16 -
Symlinks that do not depend on libpq version:
for cmd in psql pg_dump pg_restore; do ln -s ../opt/libpq/bin/$cmd /usr/local/bin/$cmd; done– David Hull Aug 23 at 22:13
Homebrew only really has the postgres formula, and doesn't have any specific formula that only installs the psql tool.
So the "correct way" to get the psql application is indeed to install the postgres formula, and you'll see toward the bottom of the "caveats" section that it doesn't actually run the database, it just puts the files on your system:
$ brew install postgres
==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.6.5.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring postgresql-9.6.5.sierra.bottle.tar.gz
==> /usr/local/Cellar/postgresql/9.6.5/bin/initdb /usr/local/var/postgres
==> Caveats
<snip>
To have launchd start postgresql now and restart at login:
brew services start postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
==> Summary
🍺 /usr/local/Cellar/postgresql/9.6.5: 3,269 files, 36.7MB
Now you can use psql to connect to remote Postgres servers, and won't be running a local one, although you could if you really wanted to.
To verify that the local postgres daemon isn't running, check your installed homebrew services:
$ brew services list
Name Status User Plist
mysql stopped
postgresql stopped
If you don't have Homebrew Services installed, just
$ brew tap homebrew/services
...and you'll get this functionality. For more information on Homebrew Services, read this excellent blog post that explains how it works.
-
1This doesn't actually answer the question, which boils down to "how do I install psql (and maybe other postgres utilities) WITHOUT installing postgres". @PPS's answer stackoverflow.com/a/49689589/2469559 is the correct one. – Benjamin R Mar 11 at 6:49
-
2IMO, this is the better option because it doesn't require the
brew linkstep. Forcing the link with libpq is necessary due to the keg_only declaration in the formula. Given this specific complication, I stand by this answer as being the "correct" way to do what the question asks. I recognize that many users will still prefer thelibpqapproach though. – Andrew Bobulsky Mar 11 at 17:17
libpq 11.2
MacOS & zsh or bash
below works
- install
libpq
brew install libpq
update PATH
if use zsh:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc source ~/.zshrcif use bash:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profile source ~/.bash_profile
-
1
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.bash_profileif you're using bash. – HenryC May 14 at 19:30 -
1
You could try brew install postgresql
But this provides a nice GUI to manage your databases https://postgresapp.com
-
1