How to Install PostgreSQL 10 on CentOS/RHEL and Fedora

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 which is highly reliable and offers data integrity and correctness to users.

In this article, we will explain how to install latest version of PostgreSQL 10 on CentOS, RHEL, Oracle Enterprise Linux, Scientific Linux and Fedora using official PostgreSQL Yum repository.

Add PostgreSQL Yum Repository

This official PostgreSQL Yum repository will combine with your Linux system and offers automatic updates for all supported versions of PostgreSQL on RedHat based distributions such as CentOS, Scientific Linux and Scientific Linux, as well as current versions of Fedora.

Note that due to the shorter Fedora support cycle, not all versions are available and we suggest that do not use Fedora for server deployments.

To use the yum repository, follow these steps:

--------------- On RHEL/CentOS 7 and Scientific Linux/Oracle Linux 7 --------------- 
# yum install

--------------- On 64-Bit RHEL/CentOS 6 and Scientific Linux/Oracle Linux 6 --------------- 
# yum install

--------------- On 32-Bit RHEL/CentOS 6 and Scientific Linux/Oracle Linux 6 --------------- 
# yum install

--------------- On Fedora 26 --------------- 
# dnf install

--------------- On Fedora 25 --------------- 
# dnf install

--------------- On Fedora 24 --------------- 
# dnf install
Enable PostgreSQL Yum Repository
Enable PostgreSQL Yum Repository

Install PostgreSQL Server

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

# yum install postgresql10-server postgresql10   [On RedHat based Distributions]
# dnf install postgresql10-server postgresql10   [On Fedora Linux]
Install PostgreSQL Server
Install PostgreSQL Server

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

Initialize PostgreSQL Database

Due to some policies for Red Hat based distributions, the PostgreSQL installation will not be active for automatic start or have the database initialized automatically. To complete your database installation, you need to initialize your database before using it for first time.

# /usr/pgsql-10/bin/postgresql-10-setup initdb
Initialize PostgreSQL Database
Initialize PostgreSQL Database

Start and Enable PostgreSQL Server

After database initialize completes, start PostgreSQL service and enable PostgreSQL service to auto start on system boot.

--------------- On SystemD --------------- 
# systemctl start postgresql-10
# systemctl enable postgresql-10
# systemctl status postgresql-10 

--------------- On SysVinit --------------- 
# service postgresql-10 start
# chkconfig postgresql-10 on
# service postgresql-10 status
Start PostgreSQL Server
Start PostgreSQL Server

Verify PostgreSQL Installation

After installing PostgreSQL 10 on your server, verify its installation by connecting to postgres database server.

# su - postgres
$ psql

psql (10.0)
Type "help" for help.

If you want you can create a password for user postgres for security purpose.

postgres=# \password postgres
Set PostgreSQL User Password
Set PostgreSQL User Password

You can find more information at the PostgreSQL Homepage:

Also check out these articles about popular database management systems:

  1. How to Install and Secure MariaDB 10 in CentOS 7
  2. How to Install and Secure MariaDB 10 in CentOS 6
  3. Install MongoDB Community Edition 3.2 on Linux Systems

That’s all! Hope you find this article useful. If you have any questions or thoughts to share, use the comment section below.

If you read this far, tweet to the author to show them you care. Tweet a thanks
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.

5 thoughts on “How to Install PostgreSQL 10 on CentOS/RHEL and Fedora”

  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.