Homebrew calls itself 'the missing package manager for macOS'. It can be used to build and install applications and libraries. Once installed, you can use the brew
command to install PostgreSQL and it's dependencies as follows:
brew update
brew install postgresql
Homebrew generally installs the latest stable version. If you need a different one then brew search postgresql
will list the versions available. If you need PostgreSQL built with particular options then brew info postgresql
will list which options are supported. If you require an unsupported build option, you may have to do the build yourself, but can still use Homebrew to install the common dependencies.
Start the server:
brew services start postgresql
Open the PostgreSQL prompt
psql
If psql complains that there's no corresponding database for your user, run createdb
.