You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Before you can work with PostgreSQL you need to install the server and the client tools on your machine. This lesson walks through installation on macOS, Linux (Ubuntu/Debian), and Windows, then verifies the installation.
The easiest method on macOS is Homebrew. If you do not have Homebrew, install it first from brew.sh.
# Install PostgreSQL (latest stable)
brew install postgresql@16
# Add the bin directory to your PATH (add this line to ~/.zshrc or ~/.bashrc)
export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH"
# Start the service
brew services start postgresql@16
Alternatively, download the graphical installer from the official PostgreSQL website (postgresql.org/download/macosx).
# Update the package list
sudo apt update
# Install the server and client packages
sudo apt install -y postgresql postgresql-contrib
# The service starts automatically; verify it
sudo systemctl status postgresql
# Enable it to start on boot
sudo systemctl enable postgresql
Download the interactive installer from postgresql.org/download/windows. The installer includes:
Run the installer, choose an installation directory, set a password for the postgres superuser, and accept the default port 5432.
After installation, confirm the server is running and the client tools are available:
# Check the PostgreSQL version
psql --version
# Connect as the default superuser
# On macOS/Linux:
psql -U postgres
# On Linux if you get a peer authentication error, switch to the postgres OS user first:
sudo -u postgres psql
If you see the psql prompt (postgres=#) the installation succeeded.
PostgreSQL creates an OS user and a database superuser both named postgres during installation. This superuser can create databases, roles, and other superusers. You should create a dedicated role for your application rather than connecting as postgres in production.
By default PostgreSQL listens on port 5432. You can verify this with:
# On Linux
sudo ss -tlnp | grep 5432
# On macOS
lsof -i :5432
With the server running and psql accessible, you are ready to start managing databases in the next lesson.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.