Installing PostgreSQL
You can install PostgreSQL from your package manager, an installer, or Docker.
In this page:
Installing PostgreSQL
On Linux use apt or dnf, on macOS use Homebrew or Postgres.app, and on Windows use the EnterpriseDB installer. Docker is the fastest way to try it: run the official postgres image with a password and map port 5432.
The installer also creates a postgres superuser.
Note:
Docker gives you a disposable PostgreSQL in one command.
Example: Installing PostgreSQL
# Ubuntu / Debian
$ sudo apt update && sudo apt install postgresql
$ sudo systemctl status postgresql
# Docker (any OS)
$ docker run --name pg -e POSTGRES_PASSWORD=secret -p 5432:5432 -d postgres:16
$ docker exec -it pg psql -U postgres
psql (16.2)
postgres=#
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Forgetting to set a password for the postgres user
- Exposing port 5432 to the internet
- Confusing the OS user with the database role
Chapter Summary
- Install with apt, brew, an installer or Docker
- Default port is 5432
- A postgres superuser is created
- Always set a strong password
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: