Installing PostgreSQL on Windows, Linux, and macOS – A Complete Guide
PostgreSQL is a powerful, open-source relational database management system (RDBMS) known for its reliability, scalability, and advanced features. Whether you're a developer, data analyst, or database administrator, installing PostgreSQL on your preferred operating system is straightforward.
This guide covers step-by-step installation instructions for Windows, Linux (Ubuntu/Debian & CentOS/RHEL), and macOS.
1. Installing PostgreSQL on Windows
Method 1: Graphical Installer (Recommended)
-
Download the Installer
-
Visit the PostgreSQL Downloads page.
-
Select the latest version and download the installer (e.g.,
postgresql-16.X-windows-x64.exe).
-
-
Run the Installer
-
Double-click the downloaded
.exefile. -
Follow the setup wizard, choosing:
-
Installation directory (default:
C:\Program Files\PostgreSQL\16) -
Components (PostgreSQL Server, pgAdmin, Command Line Tools)
-
Data directory (default:
C:\Program Files\PostgreSQL\16\data) -
Set a password for the
postgressuperuser -
Port (default:
5432)
-
-
-
Complete Installation
-
The installer will set up PostgreSQL and optionally launch pgAdmin (a GUI management tool).
-
-
Verify Installation
-
Open pgAdmin from the Start Menu
-
Connect to the server using the password you set
-
Alternatively, use psql (PostgreSQL CLI):
psql -U postgres -h localhost(Enter your password when prompted.)
-
2. Installing PostgreSQL on Linux (Ubuntu/Debian & CentOS/RHEL)
Ubuntu/Debian (apt)
-
Add PostgreSQL Repository & Update Packages
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt update -
Install PostgreSQL
sudo apt install postgresql postgresql-contrib -y -
Start & Enable PostgreSQL
sudo systemctl start postgresql sudo systemctl enable postgresql -
Verify Installation
sudo -u postgres psql -c "SELECT version();"
CentOS/RHEL (dnf/yum)
-
Enable PostgreSQL Repository
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm -
Install PostgreSQL
sudo dnf install postgresql16-server postgresql16-contrib -y -
Initialize & Start PostgreSQL
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb sudo systemctl enable postgresql-16 sudo systemctl start postgresql-16 -
Verify Installation
sudo -u postgres psql -c "SELECT version();"
3. Installing PostgreSQL on macOS
Method 1: Using Homebrew (Recommended)
-
Install Homebrew (if not installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -
Install PostgreSQL
brew install postgresql -
Start PostgreSQL Service
brew services start postgresql -
Access PostgreSQL
psql postgres
Method 2: Using PostgreSQL.app (GUI)
-
Download PostgreSQL.app (drag-and-drop installer)
-
Launch and initialize the database
-
Use
psqlfrom the terminal or GUI tools like pgAdmin
Post-Installation Steps (All OS)
-
Create a New User & Database
sudo -u postgres createuser --interactive sudo -u postgres createdb mydb -
Connect via
psqlpsql -U username -d mydb -h localhost -
Enable Remote Access (if needed)
Modifypg_hba.confandpostgresql.conf(usually in/etc/postgresql/16/main/on Linux)
Conclusion
PostgreSQL is easy to install across Windows, Linux, and macOS.
-
Windows: Use the graphical installer
-
Linux: Use
apt(Debian/Ubuntu) ordnf(CentOS/RHEL) -
macOS: Use
brewor PostgreSQL.app
Once installed, you can start developing applications, managing data, or learning SQL with one of the most powerful open-source databases available.
Need help? Drop a comment below.

Comments
Post a Comment