Learn how to install PostgreSQL on Linux i.e. on CentOS  7 & other RHEL based Linux distributions. PostgreSQL or Postgres is a very powerful, highly scalable relational database system, that provided the implementation of SQL query language. It is open source & can be installed on Unix/Linux systems as well as on Windows systems. It is a popular choice for small & large organizations alike. Let's start the process of installing PostgreSQL on Linux (CentOS & other REDHAT based distributions).

Recommended Read : MongoDB installation & configuration on RHEL/CentOS

Also Read: Installing & Configuring MariaDB on RHEL/CentOS


Installing PostgreSQL on Linux (CentOS 7, RHEL 7)

The process of installing PostgreSQL on Linux (CentOS, RHEL) requires the use of the default package manager i.e. yum. We will be discussing how we can install PostgreSQL with yum using,

1- Default repositories
2- Official PostgreSQL repositories

1- Install PostgreSQL using default yum repositories

Default repositories of the CentOS server contain the packages for Postgres & we can install them with the following command,

# yum install postgresql-server postgresql-contrib -y

Now after the packages have been installed, we need to initialize the DB to use it the first time. For that, we will use the following command,

# postgresql-setup initdb

Now start the database service & enable it for boot time,

# systemctl start postgresql
# systemctl enable postgresql

Now the downside for installing with this method is that we will not get the latest version of Postgres (this will provide version 9.2) If we need to install the latest stable version of Postgres, then we need to install PostgreSQL using the official repositories.

2- Install PostgreSQL using the official repository

For this method, we will first add the official repo for Postgres on our system with the following command,

# yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

Now we will install PostgreSQL,

# yum install postgresql10-server postgresql10

The next step is to initialize the database, same as we did above,

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

& then start the service & enable it for boot time,

# systemctl start postgresql-10
# systemctl enable postgresql-10

We now have the latest version of PostgreSQL installed on our system & this completes our tutorial on how to install PostgreSQL on Linux (CentOS 7). In our next tutorial, we will learn some important commands that are used for PostgreSQL administration. As for this tutorial, please do leave your valuable feedback or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.