DEV Community

Saif Uddin
Saif Uddin

Posted on

How to install PostgreSQL on macOS: Step-by-Step Instructions

If you're using macOS, the steps to install PostgreSQL and set up your environment are slightly different. Here's how to do it:

✅ Step 1: Install PostgreSQL on macOS

Option 1: Using Homebrew (Recommended)

1) Install Homebrew (if you haven’t already):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

2) Install PostgreSQL:

brew install postgresql
Enter fullscreen mode Exit fullscreen mode

3) Start PostgreSQL service:

brew services start postgresql
Enter fullscreen mode Exit fullscreen mode

4) Initialize the database (if needed):

initdb /usr/local/var/postgres

Enter fullscreen mode Exit fullscreen mode

5) Verify installation:

psql --version
Enter fullscreen mode Exit fullscreen mode

✅ Step 2: Create a Database and User

1) Enter PostgreSQL CLI:

psql postgres
Enter fullscreen mode Exit fullscreen mode

2) Create a new database:

CREATE DATABASE mydb;
Enter fullscreen mode Exit fullscreen mode

3) Create a new user (optional):

CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword';
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
Enter fullscreen mode Exit fullscreen mode

Exit with \q.

✅ Step 3: Browse PostgreSQL Data
Option 1: Using psql CLI
Connect to your database:

psql -d mydb -U myuser
Enter fullscreen mode Exit fullscreen mode

You can now run SQL queries directly in the terminal.

Option 2: Use a GUI Client
🔹 DBeaver (Free, powerful)

Download: https://dbeaver.io/download/
Enter fullscreen mode Exit fullscreen mode

🔹 pgAdmin (Official GUI)

Download: https://www.pgadmin.org/download/
Enter fullscreen mode Exit fullscreen mode

🔹 TablePlus (Modern UI for macOS)

Download: https://tableplus.com/
Enter fullscreen mode Exit fullscreen mode

After installing, connect with:
Host: localhost
Port: 5432
User: myuser (or postgres)
Password: your password
Database: mydb

Top comments (0)