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)

  1. Download the Installer

    • Visit the PostgreSQL Downloads page.

    • Select the latest version and download the installer (e.g., postgresql-16.X-windows-x64.exe).

  2. Run the Installer

    • Double-click the downloaded .exe file.

    • 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 postgres superuser

      • Port (default: 5432)

  3. Complete Installation

    • The installer will set up PostgreSQL and optionally launch pgAdmin (a GUI management tool).

  4. 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)

  1. 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
    
  2. Install PostgreSQL

    sudo apt install postgresql postgresql-contrib -y
    
  3. Start & Enable PostgreSQL

    sudo systemctl start postgresql
    sudo systemctl enable postgresql
    
  4. Verify Installation

    sudo -u postgres psql -c "SELECT version();"
    

CentOS/RHEL (dnf/yum)

  1. 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
    
  2. Install PostgreSQL

    sudo dnf install postgresql16-server postgresql16-contrib -y
    
  3. Initialize & Start PostgreSQL

    sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
    sudo systemctl enable postgresql-16
    sudo systemctl start postgresql-16
    
  4. Verify Installation

    sudo -u postgres psql -c "SELECT version();"
    

3. Installing PostgreSQL on macOS

Method 1: Using Homebrew (Recommended)

  1. Install Homebrew (if not installed)

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Install PostgreSQL

    brew install postgresql
    
  3. Start PostgreSQL Service

    brew services start postgresql
    
  4. Access PostgreSQL

    psql postgres
    

Method 2: Using PostgreSQL.app (GUI)

  • Download PostgreSQL.app (drag-and-drop installer)

  • Launch and initialize the database

  • Use psql from 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 psql

    psql -U username -d mydb -h localhost
    
  • Enable Remote Access (if needed)
    Modify pg_hba.conf and postgresql.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) or dnf (CentOS/RHEL)

  • macOS: Use brew or 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

Popular posts from this blog

PostgreSQL Architecture Explained: A Deep Dive into How PostgreSQL Works

Connecting to PostgreSQL Using psql: The Definitive Guide