How to install PostgreSQL on Kali Linux

In this article, we will see how to install PostgreSQL on Kali Linux step by step. In this article, we will perform below steps:
1. Install PostgreSQL on Kali Linux.
2. PostgreSQL post installation steps(Enable, start the PostgreSQL service).
3. Connect to PostgreSQL server on Kali Linux.

Install PostgreSQL on Kali Linux

1. Go to PostgreSQL official website. There we can find the commands to be performed to install PostgreSQL on Kali Linux distribution.

Note: Kali Linux is debian type family ditribution.

2. Create the file repository configuration:

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

How to install PostgreSQL on Kali Linux

3. Import the repository signing key:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

4. Update the package lists:

sudo apt-get update

5. Install the latest version of PostgreSQL 14. If we want to install older version, assume 12, then replace postgresql-14 with postgresql-12 in the below command.

sudo apt-get -y install postgresql-14

We have successfully installed PostgreSQL on Kali Linux. Now, check the status of PostgreSQL, start it and connect to PostgreSQL server on Kali Linux.

PostgreSQL post installation steps on Kali Linux

1. Verify PostgreSQL status on Kali Linux.

sudo systemctl status postgresql

2. Enable the PostgreSQL service on Kali Linux.

sudo systemctl enable postgresql

3. Start the PostgreSQL server on Kali Linux.

sudo systemctl start postgresql

Connect to PostgreSQL on Kali Linux

1. Switch to postgres user by running below command.

sudo su - postgres

2. Run the command psql from terminal.

3. We can get verify the PostgreSQL version installed on Kali Linux by running below command.

select version();

4. We can verify list of databases installed by default with PostgreSQL server by running below command.

\l

5. We can create database by running below command.

create database r2schools;

So in this article, we have performed PostgreSQL installation, started and connected to PostgreSQL on Kali Linux.