← Back to PostgreSQL Course | Chapter 1: Introduction | Lesson 3 of 7

Installing PostgreSQL

You can install PostgreSQL from your package manager, an installer, or Docker.

In this page:

  1. Installing PostgreSQL

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

bash
# 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
  1. Forgetting to set a password for the postgres user
  2. Exposing port 5432 to the internet
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.