Install PostgreSQL on Linux, macOS and Windows
Install the PostgreSQL server and the psql client on each desktop OS, start the service, connect as the postgres superuser and create your first database and user.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
Which option to pick
For a local development database, install the PostgreSQL server and client together from your package manager. On Linux the distribution package is fine for development; the PostgreSQL project’s own apt and yum repositories (PGDG) give you the newest major version and several side by side. On macOS Homebrew is the easiest, and Postgres.app is a good graphical alternative. On Windows the EDB installer from postgresql.org is the standard. If you already use Docker, docker run postgres:17 is another perfectly good way to get a local server without installing anything; see the Compose entry. Replace 17 below with the current major version.
Step: Linux
Debian and Ubuntu, distribution package:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo apt update
sudo apt install postgresql
sudo systemctl status postgresql
To use the PostgreSQL project’s repository for a specific version instead, the postgresql-common package ships a helper that configures it:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo apt install postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
sudo apt install postgresql-17
Fedora and RHEL need an explicit initialisation step and the service enabled:
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo dnf install postgresql-server postgresql-contrib
sudo postgresql-setup --initdb
sudo systemctl enable --now postgresql
Step: macOS
brew install postgresql@17
brew services start postgresql@17
Homebrew creates a database cluster owned by your macOS user, so psql postgres connects straight away without a password. If psql is not found, Homebrew prints the PATH line to add for versioned formulas, typically export PATH="$(brew --prefix)/opt/postgresql@17/bin:$PATH". Alternatively install Postgres.app, start it, and follow its instructions to add the command-line tools to PATH.
Step: Windows
winget install PostgreSQL.PostgreSQL.17
Or download the interactive installer from postgresql.org/download/windows. It asks for a password for the postgres superuser; write it down. It installs the server as a Windows service, pgAdmin, and SQL Shell (psql) in the Start menu. To use psql from PowerShell, add C:\Program Files\PostgreSQL\17\bin to your PATH in the environment variable settings.
Check it works
psql --version
pg_isready
pg_isready prints accepting connections when the server is up. Connect as the superuser and create a user and database for your project. On Linux the postgres OS user is allowed in without a password (peer authentication):
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo -u postgres psql
On macOS with Homebrew use psql postgres; on Windows use psql -U postgres and the password from the installer. Then, inside psql:
CREATE USER app WITH PASSWORD 'choose-a-password';
CREATE DATABASE app OWNER app;
\q
psql -h localhost -U app -d app
Common problems
psql: error: connection to server on socket ... failed: FATAL: role "yourname" does not exist: plainpsqltries to log in with your OS user name. Usesudo -u postgres psqlorpsql -U app -d app.Peer authentication failed for user "app"on Linux: you connected through the Unix socket, where Linux user names must match. Add-h localhostto use a password instead.connection refusedon port 5432: the service is not running.sudo systemctl start postgresqlon Linux,brew services start postgresql@17on macOS, or start the service in services.msc on Windows.- Windows:
psqlis not recognised: thebinfolder is not onPATH; use SQL Shell from the Start menu or add the folder as described above. - Port 5432 already in use: another PostgreSQL (or a Docker container) is running. Stop it or configure a different
portinpostgresql.conf.
Official documentation
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0198 Install PostgreSQL and connect with psql on Debian, Ubuntu and RHEL Install the PostgreSQL server from your distribution or the official PGDG repositories, start it, and open your first psql session as the… Beginner · Step by step · Linux Article Install & connect 15 Oct 2026
- 0199 psql meta-commands cheat sheet The backslash commands you use every day in psql: connecting, listing databases, tables and roles, describing objects, timing queries, expanded output and… Beginner · Cheat sheet · Any system Article Install & connect · Roles & administration 15 Oct 2026
- 0201 pg_hba.conf and PostgreSQL authentication methods pg_hba.conf decides who may connect from where and how they must prove who they are. Rules are checked top to bottom and… Intermediate · Explains an idea · Linux Article Install & connect · Security & access 15 Oct 2026
- 0210 Fix: FATAL: no pg_hba.conf entry for host The server received the connection but no pg_hba.conf rule matches this client address, user, database and SSL mode. Add or correct a… Intermediate · Fixes an error · Linux Article Install & connect · Security & access 15 Oct 2026
- 0211 Fix: psql connection to server on socket /var/run/postgresql/.s.PGSQL.5432 failed psql tried the local Unix socket and found nothing there. The server is not running, listens on another port, or uses a… Beginner · Fixes an error · Linux Article Install & connect 15 Oct 2026
- 0257 Run PostgreSQL properly on a Linux server: install, lock down, back up, monitor and patch Set up PostgreSQL 18 from the official repository for one application: a dedicated role and database, SCRAM logins from one app server… Intermediate · Guided project · Linux Article Backup & restore · Install & connect · Roles & administration 15 Oct 2026
Repos in the wild
- postgres/postgres: PostgreSQL source code mirror postgres/postgres The official read-only GitHub mirror of the PostgreSQL source repository. Browse the code and history here; patches go through the project's mailing lists, not pull requests. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +3,708 chars