In this tutorial, you will learn how to install PostgreSQL on Debian unstable, Debian 10, Debian 11 and Debian 12.
PostgreSQL is an open source database that you can use on your server.
PostgreSQL provides a repository for Debian users, all you have to do is add the repository on your Debian machine, and install PostgreSQL via the terminal.
The PostgreSQL apt repository that we'll be using for this tutorial, supports all Debian versions such as: Debian sid(unstable), Debian 10, Debian 11 and Debian 12. So, you can easily use one repository for any of the Debian versions we mentioned above.
Step 1 - Import PostgreSQL GPG Key
First thing that you need to do is importing the GPG key for PostgreSQL on your Debian machine, so that you can install PostgreSQL using the official repository.
To do so, run the command below.
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Step 2 - Setup PostgreSQL Repository
Next, proceed to setup PostgreSQL repository on your system. Setting up a repository on Debian is very simple, and it can be done easily from the terminal.
To add PostgreSQL apt repository on your machine, run the following.
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Step 3 - Update your Debian system
In order to be able to use the new PostgreSQL apt repository that you added on your system, first you must update the package index.
Updating allows your system to use PostgreSQL repository. To do so, simply update your Debian machine with.
sudo apt update
Step 4 - Install PostgreSQL
The GPG and PostgreSQL repository should now be added and enabled on your system. This means you can now proceed to install PostgreSQL.
To install PostgreSQL, you can do so by running the command below.
sudo apt -y install postgresql
In this tutorial, you learned how to install PostgreSQL on Debian unstable, Debian 10, Debian 11 and Debian 12.