How to Install PostgreSQL 16 and pgAdmin on Debian 12

Take Your Linux Skills to the Next Level All courses, certifications, ad-free articles & community — from $8/mo
Join Root →
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Access to Linux certifications (RHCSA, RHCE, LFCS and LFCA)
Access new courses on release
Get access to weekly newsletter
Priority help in comments
Private Telegram community
Connect with the Linux community
From $8/mo · or $59/yr billed annually · Cancel anytime

PostgreSQL is a powerful, highly scalable, open source, and cross-platform object-relational database system that runs on Unix-like operating systems including Linux and Windows OS. It is an enterprise-level database system that is highly reliable and offers data integrity and correctness to users.

In this step-by-step tutorial, we will show you how to install PostgreSQL 16 and pgAdmin (graphical database management tool) on Debian 12 Linux.

1. Updating Debian System

Before installing PostgreSQL, make sure to update your Debian package list and upgrade existing packages using the following apt commands.

sudo apt update
sudo apt upgrade
Upgrade Debian System
Upgrade Debian System

2. Add PostgreSQL Repository on Debian

The official PostgreSQL APT Repository will combine with your Linux system and offer automatic updates for all supported versions of PostgreSQL throughout their support lifetime.

First, add the PostgreSQL repository, import the repository signing key, and update the package lists as shown.

sudo sh -c 'echo "deb https://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
Add PostgreSQL Repository to Debian
Add PostgreSQL Repository to Debian

3. Install PostgreSQL 16 on Debian

Once you have added the PostgreSQL APT Repository, install the PostgreSQL 16 server with the following command.

$ sudo apt install postgresql-16 
Install PostgreSQL on Debian
Install PostgreSQL on Debian

The PostgreSQL data directory /var/lib/postgresql/16/main/ contains all of the data files for the database.

4. Manage PostgreSQL Service

To start, enable, and check the status of the PostgreSQL service, use the following commands.

sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service 
sudo systemctl status postgresql.service 
Check PostgreSQL Running Status
Check PostgreSQL Running Status

5. Verify PostgreSQL Installation

After installing the PostgreSQL database system on your server, verify its installation by connecting to postgres database server. The PostgreSQL administrator user is named as postgres, type this command to access the user system account.

sudo su postgres
cd
psql
Connect to PostgreSQL Shell
Connect to PostgreSQL Shell

6. Set Postgres User Password

To set a password for the postgres database administrator user, use the following command.

\password postgres

After running the above command, you will be prompted to enter the new password.

Set Postgres Password
Set Postgres Password

Once you’ve set the password, exit the PostgreSQL prompt.

\q
exit

7. Install pgAdmin in Debian

pgAdmin is a popular graphical user interface (GUI) for managing PostgreSQL databases and it is used for creating, editing, and managing databases, tables, users, and other database objects.

To install pgAdmin, you need to install the public key for the repository with the following curl command.

curl -fsS https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo gpg --dearmor -o /usr/share/keyrings/packages-pgadmin-org.gpg

Next, create the repository configuration file with the following command.

sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/packages-pgadmin-org.gpg] https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
Install Pgadmin Repository
Install Pgadmin Repository

Next, install the pgAdmin as shown.

sudo apt install pgadmin4
Install pgAdmin on Debian
Install pgAdmin on Debian

Afterward, you’ll have to execute a web setup script to configure the pgadmin4 for web mode operation as shown.

sudo /usr/pgadmin4/bin/setup-web.sh
Configure Pgadmin for Web Mode
Configure Pgadmin for Web Mode

Now, launch your web browser and enter the following URL to reach the pgAdmin4 login web interface.

http://your-server-ip/pgadmin4
OR
http://localhost/pgadmin4
pgAdmin User Login
pgAdmin User Login

Enter your email address and password, then click the Login button to view the pgAdmin4 dashboard page.

pgAdmin Dashboard
pgAdmin Dashboard

Finally, read through these related articles about the PostgreSQL database management system:

Conclusion

You have now successfully installed PostgreSQL 16 and pgAdmin on Debian 12. You can now start using pgAdmin to manage your PostgreSQL databases.

Root Plan
Premium Linux Education for Serious Learners

Take Your Linux Skills to the Next Level

Root members get full access to every course, certification prep track, and a growing library of hands-on Linux content — with new courses added every month.

What You Get
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Access to Linux certifications (RHCSA, RHCE, LFCS and LFCA)
Access new courses on release
Get access to weekly newsletter
Priority help in comments
Private Telegram community
Connect with the Linux community
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Root Plan Premium Linux Education for Serious Learners

Before You Go - Upgrade Your Linux Skills

Root members get everything in one place, with new courses added every month.

What You Get
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Linux certifications: RHCSA, RHCE, LFCS and LFCA
Access new courses on release
Weekly newsletter, priority support & Telegram community
Join Root Today and Start Learning Linux the Right Way
Structured courses, certification prep, and a community of Linux professionals - all in one membership.
Join Root Plan →
$8/mo · or $59/yr billed annually