How to install Postgres in PostgreSQL

Galaxy Glossary

How do I install PostgreSQL quickly on macOS, Linux, or Windows?

Install PostgreSQL server and client tools on macOS, Linux, or Windows so you can create databases and run SQL.

Sign up for the latest in SQL knowledge from the Galaxy Team!

Description

What are the fastest ways to install PostgreSQL on each OS?

Use your operating system’s package manager. Homebrew on macOS, APT on Ubuntu/Debian, YUM/DNF on RHEL/CentOS/Fedora, and the interactive installer on Windows give you the shortest path from zero to a running database.

How do I install PostgreSQL on macOS with Homebrew?Run brew install postgresql. Homebrew downloads the latest stable version, compiles if needed, and registers the service. Start it with brew services start postgresql, then verify with psql -V.

How do I install PostgreSQL on Ubuntu or Debian?

Add the official PostgreSQL APT repo for newer versions:

sudo apt update
sudo apt install curl ca-certificates gnupg
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/pg.asc
echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt install postgresql-16

The service starts automatically. Test with sudo -u postgres psql -c "SELECT version();".

How do I install PostgreSQL on RHEL, CentOS, or Fedora?

Enable the PostgreSQL repository, then install:

sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %rhel)-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql16-server
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable --now postgresql-16

Confirm with psql --version.

How do I install PostgreSQL on Windows?

Download the EnterpriseDB installer, run it, choose components (server, pgAdmin, command-line tools), set a superuser password, port (5432), and locale. After installation, open psql from the Start Menu or connect using pgAdmin.

What ports, users, and data directories are created?

Default port is 5432. A system user and database role named postgres is created. Data lives in /usr/local/var/postgres (macOS), /var/lib/postgresql/<version>/main (Debian/Ubuntu), or /var/lib/pgsql/16/data (RHEL-based).

How do I connect to the new server?

psql -h localhost -U postgres

If ident/peer auth is enabled, omit -U and connect as the OS user.

How do I enable autostart on boot?

Homebrew runs brew services start postgresql. Systemd systems use systemctl enable --now postgresql (or postgresql-16 if multiple versions). Windows installs a background service automatically.

Best practices after installation?

  • Create an unprivileged role for daily work (createuser --interactive --pwprompt dev).
  • Switch from password to certificate or IAM auth in production.
  • Backup with pg_dump and pg_basebackup regularly.
  • Configure shared_buffers, work_mem, and WAL settings to match RAM and workload.

What is the exact install syntax for each platform?

# macOS
brew install postgresql

# Ubuntu/Debian (default repo)
sudo apt update && sudo apt install postgresql

# RHEL/CentOS (default repo)
sudo dnf install postgresql-server
sudo postgresql-setup --initdb

# Windows (PowerShell winget)
winget install PostgreSQL.PostgreSQL

How can I verify the installation?

Check the service status: systemctl status postgresql or brew services list. Then run psql -c "SELECT version();"; you should see server and client versions.

Why How to install Postgres in PostgreSQL is important

How to install Postgres in PostgreSQL Example Usage


psql -U postgres -d postgres -c "SELECT 'PostgreSQL installation successful' AS status;"

How to install Postgres in PostgreSQL Syntax


# macOS
brew install postgresql
brew services start postgresql

# Ubuntu/Debian
sudo apt update
sudo apt install postgresql-[VERSION]

# RHEL/CentOS/Fedora
yum install postgresql[VERSION]-server
/usr/pgsql-[VERSION]/bin/postgresql-[VERSION]-setup initdb
systemctl enable --now postgresql-[VERSION]

# Windows (winget)
winget install PostgreSQL.PostgreSQL

Common Mistakes

Frequently Asked Questions (FAQs)

Can I install multiple PostgreSQL versions side by side?

Yes. Use version-specific packages (e.g., postgresql-15, postgresql-16) or Homebrew’s brew install postgresql@15. Bind each instance to a different port.

Does installation create a database superuser?

Every installer creates a role named postgres with superuser privileges. Protect its password or disable remote login.

How do I uninstall PostgreSQL completely?

Stop the service, remove packages (brew uninstall postgresql or sudo apt purge postgresql*), then delete the data directory. Backup before removal.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo