How to Install PostgreSQL 16 on RHEL-Based Distributions

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 article, we will explain how to install the latest version of PostgreSQL 16 on RHEL and RHEL-based distributions such as Rocky Linux, AlmaLinux, Oracle Linux, and Fedora using the official PostgreSQL Yum repository.

1. Update Software Package

Before initiating the PostgreSQL installation process, make sure to update your Linux system software packages by running the following dnf command.

sudo dnf update
Update System Packages
Update System Packages

2. Enabling PostgreSQL Repository

While PostgreSQL is available in the default system repositories, it’s advisable to enable the official PostgreSQL repository for access to the latest version.

On RHEL, Rocky, AlmaLinux, and Oracle Linux 9:

sudo dnf install -y

On RHEL, Rocky, AlmaLinux, and Oracle Linux 8:

sudo dnf install -y

On Fedora 39:

sudo dnf install -y

On Fedora 38:

sudo dnf install -y

3. Installing PostgreSQL 16 Server

After adding the PostgreSQL repository in your respective Linux distribution, use the following command to install the PostgreSQL server and client packages.

sudo dnf install -y postgresql16-server postgresql16
Install PostgreSQL Server
Install PostgreSQL Server

Important: PostgreSQL data directory /var/lib/pgsql/16/data/ contains all of the data files for the database.

4. Initializing PostgreSQL Database

Because of certain policies applicable to Red Hat-based distributions, the PostgreSQL installation will not automatically start or have the database initialized as part of the automatic startup process.

To complete your database installation, you need to initialize your database before using it for the first time.

sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
Initializing PostgreSQL Database
Initializing PostgreSQL Database

5. Configuring PostgreSQL for Remote Access

To enable remote connections, you need to modify the configuration file postgresql.conf using a text editor.

sudo vi /var/lib/pgsql/16/data/postgresql.conf

Update the listen_addresses parameter to allow connections from all hosts on your local network.

listen_addresses = '*'
Enable PostgreSQL Remote Access
Enable PostgreSQL Remote Access

After making the changes to the configuration file, you need to restart the PostgreSQL service to apply the new settings and enable automatic start.

sudo systemctl restart postgresql-16
sudo systemctl enable postgresql-16

6. Setting PostgreSQL User Password

Set the password for the default PostgreSQL user (postgres).

sudo passwd postgres
Set PostgreSQL User Password
Set PostgreSQL User Password

7. Accessing PostgreSQL Database

After setting the user password, you can access the PostgreSQL database server using the psql command.

sudo -i -u postgres
Connecting to PostgreSQL
Connecting to PostgreSQL

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


Congratulations! You’ve successfully installed PostgreSQL 16 on RedHat-based distributions (the latest version available at the time). Remember to consult the official PostgreSQL documentation for any version-specific details or changes.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

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.


Leave a Reply
  1. CentOS 6.9:

    Instead of this:

    # /usr/pgsql-10/bin/postgresql-10-setup initdb

    You need to run this:

    # service postgresql-10 initdb

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.