This article will instruct you how to install the PostgreSQL database server on Linux – Red Hat/Fedora, Ubuntu, Debian, and Arch Linux.
Installing PostgreSQL on Debian Linux
Here’s now to install PostgreSQL on the Debian Linux distribution (and distributions based on it):
From the Default apt Repository
You can install PostgreSQL server straight by the apt software repository on Debian Linux by running:
sudo apt-get install postgresql-12
Note the use of the sudo command to run the package installation as the root (administrative) user.
Installing More Recent Versions From the PostgreSQL apt Repository
The version of PostgreSQL included in the default Debian apt software repository is most likely an older version. If you want the latest features, it’s best to add the PostgreSQL repository and install from there.
To do so, run the following commands:
# Create repository configuration file sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' # Import repository signing key wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - # Update package lists sudo apt-get update # Install latest version of PostgreSQL sudo apt-get -y install postgresql
Installing PostgreSQL on Ubuntu Linux
Installing PostgreSQL on Ubuntu is the same as on Debian. Again, we recommend installing form the PostgreSQL apt repository so you get the latest features.
Installing PostgreSQL on Arch Linux
Install the PostgreSQL server package from the Arch official repository by running:
pacman -S postgresql
The version of PostgreSQL available in the Arch repository is usually more recent than the one provided for Ubuntu/Debian, but if you want to install a different/more recent version you can always build from source as detailed by in the ‘Other Linux Distributions’ section below.
Installing PostgreSQL on Red Hat/Centos/Fedora
Here’s how to install PostgreSQL on Red Hat Linux-based distributions, including Centos, Fedora, Rocky, and Oracle Linux:
Installing from the default Red Hat Repository
Red Hat based distributions all include PostgreSQL in the default repository, install this version by running the following on Red Hat 8 and Fedora:
dnf install postgresql-server
Or the following on Red Hat 6/7:
yum install postgresql-server
Installing More Recent Versions From the PostgreSQL Yum Repository
Like Debian/Ubuntu, the version of PostgreSQL server included in the official respository is likely to be outdated. If you want the latest features, you will need to add the PostgreSQL Yum Repository to your system by following the instructions here.
Installing PostgreSQL on Other Linux Distributions
If you are running a less-popular distribution of Linux that does not include PostgreSQL in its software repository, you can build from source, as detailed here.
Note that this is probably not what you want to do if you’re a beginner – if there is a packaged version of Postgres available for you, it’s recommended to use it.
Installing PostgreSQL on Windows, Mac and BSD
We’re not (too) exclusionary, and you might be coding on a Windows, Mac, or BSD. Follow the links below for install instructions for these platforms:
To continue your PostgreSQL journey, head back to our index that lists our full PostgreSQL guide.