Right, let’s get this show on the road. Installing PostgreSQL is your first real interaction with it, and thankfully, it’s mostly a painless process. The method, however, differs wildly depending on your operating system. I’ll guide you through the sanest paths for each, because yes, some are saner than others.

On Linux: Pick Your Package Manager Poison

Linux is where PostgreSQL feels most at home, and the installation is typically a one-liner. But which one-liner? That depends on your distro. I strongly recommend using the official PostgreSQL repositories instead of whatever slightly older version is languishing in your distro’s main repos. You get newer features and, more importantly, consistent security updates.

For Ubuntu/Debian, it goes like this. First, grab the repository signing key and add the repo. Don’t just blindly copy-paste from the internet; a quick check on the official PostgreSQL docs for the latest package name is always wise.

# Create the repository configuration file
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update your package list
sudo apt-get update

# Now, install PostgreSQL. Want a specific version? Use 'postgresql-16' instead.
sudo apt-get -y install postgresql

For Fedora/CentOS/RHEL, the dance is similar but with dnf. The official repos are your friend here, too.

Why do it this way? Because the packages from the PostgreSQL Global Development Group are meticulously maintained and configured to work correctly out of the box. They set up a dedicated user (postgres), configure the service to start on boot, and put the data directory and config files in the standard places. It’s the difference between building a chair from IKEA and whittling one yourself from a log.

On macOS: The Homebrew Advantage

If you’re on a Mac and you’re not using Homebrew, I have questions. Mostly, “why?” It’s the closest thing macOS has to a proper package manager. The installation is blissfully simple.

# Update Homebrew itself first. Always a good idea.
brew update

# Install PostgreSQL. This will grab the latest stable version.
brew install postgresql

# Now, tell macOS to start the service whenever you log in.
brew services start postgresql

And that’s… pretty much it. Homebrew does the heavy lifting, manages the data directory (/usr/local/var/postgres), and gives you a clean, isolated installation. The main thing to remember here is that Homebrew will install the command-line tools under its own prefix, so you might need to ensure /usr/local/bin is in your PATH before /usr/bin if you have an older version of PostgreSQL installed from elsewhere. You’ll know if you have a conflict because your terminal will suddenly become passive-aggressive about which psql it’s using.

On Windows: The Graphical Quagmire

Ah, Windows. The PostgreSQL community does a valiant job here, but the platform itself introduces some… interesting choices. The standard installer from postgresql.org is the way to go. It’s a wizard-driven affair, which feels a bit odd for a database server, but here we are.

The critical part of the installer is the password prompt for the postgres superuser account. DO NOT FORGET THIS PASSWORD. Write it down. Put it in your password manager. The installer will also ask you about the port (5432 is fine), and the locale. The default settings are sensible for most.

Now, the installer’s most questionable choice: it will insist on installing the Stack Builder utility. This is a clunky tool that tries to install additional drivers and applications. You can safely uncheck this. You don’t need it. It’s the database equivalent of being offered a timeshare after buying a car.

Once installed, the PostgreSQL service runs in the background. You’ll interact with it via the psql command in PowerShell or Command Prompt. Just remember that on Windows, the command-line utilities aren’t necessarily in your global PATH by default. You’ll often find them in C:\Program Files\PostgreSQL\<version>\bin\. Do yourself a favor and add that to your system PATH so you can run psql from anywhere without fuss.

The Universal First Step: Logging In

No matter how you installed it, your first task is to connect. The installation creates a superuser named postgres. On Linux and macOS, it often uses “ident” or “peer” authentication, which means it trusts your system username. The easiest way to connect is to switch to the postgres system user and then launch psql.

# On Linux/macOS, switch to the 'postgres' user and open the CLI
sudo -u postgres psql

On Windows, you’ll just be prompted for the password you (hopefully) remembered.

# On Windows, the user flag is typically uppercase
psql -U postgres

You’ll know it worked when you’re greeted by the postgres=# prompt. Congratulations, you’re in. Now the real fun begins. Type \q and hit enter to quit for now. We’ve got configuration to tackle next, and that’s a whole other adventure.