Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Ubuntu 22.04 - Install PostgreSQL

Similar Posts

Native Package - PostgreSQL 14


If you wish to set up a PostgreSQL 14 database server:

sudo apt update \
  && sudo apt install postgresql-14

Client Only

If you just wish to install a client to connect to other PostgreSQL servers:

sudo apt update \
  && sudo apt install postgresql-client-14

PostgreSQL Repository

If you want to install the very latest version of PostgreSQL then you will need to add their repository which can be done with the script below:

# Download the PostgreSQL public key for checking signatures of packages
sudo curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/pgsql.gpg
sudo chmod a+r /etc/apt/keyrings/pgsql.gpg

# Add the postgresql repository to our sources
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/pgsql.gpg] $(lsb_release -cs)-pgdg main" \
  | sudo tee /etc/apt/sources.list.d/pgdg.list > /dev/null

# Update the package lists:
sudo apt-get update

... then you can install whichever version you want, including version 15.

sudo apt-get -y install postgresql-15

... or if you just need the client:

sudo apt-get -y install postgresql-client-15

Check Version

If you want to check what version of PostgreSQL you are now running, use the following command:

sudo -u postgres psql postgres -c 'SELECT version()' | grep PostgreSQL

Configure It

After having installed PostgreSQL, you probably want to spend a bit of time configuring it (passwords etc).


Last updated: 3rd September 2023
First published: 17th July 2023