If you’ve installed Postgres.app on macOS but get command not found when running psql or other Postgres commands, the binary directory isn’t in your PATH.
Fix
Step 1: Add Postgres binaries to your PATH
Run this in your terminal (replacing 12 with your installed Postgres version):
1 | export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/12/bin |
To make this permanent, add the line to your shell config file (~/.zshrc for Zsh, ~/.bash_profile for Bash):
1 | echo 'export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/12/bin' >> ~/.zshrc |
Step 2: Verify
1 | psql --version |
You should see the Postgres version output without any error.
Bonus: Install the pg Ruby gem
If you’re also getting errors installing the pg gem in a Rails project after fixing the PATH:
1 | gem install pg -v '1.2.2' --source 'https://rubygems.org/' |