0
0
PostgresqlHow-ToBeginner · 4 min read

How to Install PostgreSQL on Mac: Step-by-Step Guide

To install PostgreSQL on a Mac, use the Homebrew package manager by running brew install postgresql in the Terminal. After installation, start the PostgreSQL service with brew services start postgresql and verify it with psql --version.
📐

Syntax

Use Homebrew commands in the Terminal to install and manage PostgreSQL on Mac.

  • brew install postgresql: Installs PostgreSQL.
  • brew services start postgresql: Starts PostgreSQL as a background service.
  • psql --version: Checks the installed PostgreSQL version.
bash
brew install postgresql
brew services start postgresql
psql --version
Output
psql (PostgreSQL) 15.3
💻

Example

This example shows how to install PostgreSQL, start the service, and check the version to confirm installation.

bash
brew install postgresql
brew services start postgresql
psql --version
Output
==> Downloading https://homebrew.bintray.com/bottles/postgresql-15.3.catalina.bottle.tar.gz ==> Pouring postgresql-15.3.catalina.bottle.tar.gz ==> Caveats 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 psql (PostgreSQL) 15.3
⚠️

Common Pitfalls

Common mistakes when installing PostgreSQL on Mac include:

  • Not having Homebrew installed before running the install command.
  • Forgetting to start the PostgreSQL service after installation.
  • Confusing psql commands before the service is running.
  • Not updating Homebrew before installation, which can cause outdated versions.

Always run brew update before installing to avoid version issues.

bash
Wrong way:
brew install postgresql
psql --version

Right way:
brew update
brew install postgresql
brew services start postgresql
psql --version
📊

Quick Reference

CommandDescription
brew updateUpdate Homebrew to the latest version
brew install postgresqlInstall PostgreSQL package
brew services start postgresqlStart PostgreSQL service in background
psql --versionCheck installed PostgreSQL version
brew services stop postgresqlStop PostgreSQL service

Key Takeaways

Use Homebrew to easily install PostgreSQL on Mac with simple commands.
Always run 'brew update' before installing to get the latest version.
Start the PostgreSQL service after installation to use the database.
Verify installation by checking the PostgreSQL version with 'psql --version'.
Avoid skipping service start or missing Homebrew installation to prevent errors.