How to Set Up PostgreSQL on Windows, macOS, and Linux

Galaxy Glossary

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

Install PostgreSQL locally on any major OS to start developing, testing, and running SQL databases on your machine.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

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

Use your platforms native package manager or the official graphical installer. Package managers finish in seconds, keep PostgreSQL updated automatically, and can be scripted.

Windows: Chocolatey

choco install postgresql --version 16.2 downloads the MSI, installs the server, creates a Windows service, and sets the PATH.Change --version to pin a release or omit it for the latest.

macOS: Homebrew

brew install postgresql@16 installs binaries under /opt/homebrew/opt/postgresql@16, sets up launchd for autostart, and creates the default superuser matching your macOS login.

Ubuntu/Debian: APT

sudo apt-get update && sudo apt-get install postgresql-16 adds the server, psql client, and service unit under systemd. PostgreSQL starts automatically at boot.

How do I initialize and start the cluster?

Package managers perform initdb during install.If you built from source, run initdb -D /usr/local/pgsql/data then pg_ctl -D /usr/local/pgsql/data -l logfile start.

How can I verify the installation?

Connect with psql -U postgres (Windows) or psql (Unix19s peer auth). Run SELECT version(); to confirm the server responds.

What are common post finstall tasks?

1. Change the default postgres password: \password postgres in psql.
2. Open remote access: edit postgresql.conf (listen_addresses) and pg_hba.conf (host lines).
3.Enable autostart: brew services start postgresql@16 or sudo systemctl enable --now postgresql.

Best practices for local environments?

Keep one major version, use separate roles per app, back up with pg_dumpall, and avoid superuser work in day49day development.

What mistakes should I avoid?

Skipping the PATH update blocks psql; mixing Homebrew and Postgres.app binaries causes socket conflicts.

.

Why How to Set Up PostgreSQL on Windows, macOS, and Linux is important

How to Set Up PostgreSQL on Windows, macOS, and Linux Example Usage


SELECT version();

How to Set Up PostgreSQL on Windows, macOS, and Linux Syntax


Windows (Chocolatey):
  choco install postgresql [--version <major.minor>]
macOS (Homebrew):
  brew install postgresql@<major>
Linux (APT):
  sudo apt-get install postgresql-<major>
Source build (all OS):
  ./configure && make && sudo make install
  initdb -D <data_directory>
  pg_ctl -D <data_directory> start

Common Mistakes

Frequently Asked Questions (FAQs)

Does the installer set a default password?

Windows prompts for a superuser password during setup. Unix-like installs rely on peer authentication, so no password is set until you run \password inside psql.

Can I run multiple PostgreSQL versions side by side?

Yes. Change the port in postgresql.conf for the second cluster and start each service separately. Homebrew names formulas by version to simplify this.

How do I uninstall PostgreSQL cleanly?

Reverse your package manager command: choco uninstall postgresql, brew uninstall postgresql@16, or sudo apt-get remove --purge postgresql*. Drop the data directory manually if no longer needed.

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
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.