Installing PostgreSQL on MacOS

By Ercan - 26/06/2025

If you're working on personal projects and prefer running PostgreSQL directly on your Mac instead of using Docker, you're not alone. While containerization is great for many use cases, sometimes you just want your database to live natively on your machine — especially when you care about persistent data and minimal overhead.

In this guide, I’ll walk you through installing PostgreSQL 18 using Homebrew on macOS, with separate instructions for Apple Silicon and Intel-based Macs.


Step 1: Install PostgreSQL

brew install postgresql@18

By default, Homebrew initializes a database cluster during installation. Since we want to configure it ourselves, we’ll remove the default cluster.

Step 2: Remove the Default Cluster

On Apple Silicon (ARM64):

rm -rf /opt/homebrew/var/postgresql@18

On Intel:

rm -rf /usr/local/var/postgresql@18

Step 3: Initialize a New Cluster with Custom Credentials

We’ll now create a new cluster with a postgres user and password, using scram-sha-256 authentication and UTF-8 encoding.

On Apple Silicon (ARM64):

/opt/homebrew/opt/postgresql@18/bin/initdb \
  -D /opt/homebrew/var/postgresql@18 \
  -U postgres -W \
  --locale=en_US.UTF-8 -E UTF8 -A scram-sha-256

On Intel:

/usr/local/opt/postgresql@18/bin/initdb \
  -D /usr/local/var/postgresql@18 \
  -U postgres -W \
  --locale=en_US.UTF-8 -E UTF8 -A scram-sha-256

Step 4: Run PostgreSQL Only When Needed

To preserve battery life, especially on MacBooks, I prefer not to run PostgreSQL as a background service. Instead, I start it manually when needed:

Start PostgreSQL:

brew services run postgresql@18

Stop PostgreSQL:

brew services stop postgresql@18
💡 You can also find the full command list in this GitHub Gist.

 

Tags: postgresql