Share your love
Install a Specific Version of PostgreSQL on Ubuntu 20.04: Easy Steps
This tutorial intends to teach you to Install a Specific Version of PostgreSQL on Ubuntu 20.04. To install a specific version of PostgreSQL on your server, you must add the repository and then install it. Here on the Orcacore website, we will show you to set up the latest PostgreSQL version which is PostgreSQL 16 on Ubuntu 20.04. PostgreSQL 16 has improved the performance and more features that you can use for your databases.
Table of Contents
Steps To Install a Specific Version of PostgreSQL on Ubuntu 20.04
Before you start to Install a Specific Version of PostgreSQL on Ubuntu 20.04, you must have access to your server as a non-root user with sudo privileges. To do this, you can follow this guide on Initial Server Setup with Ubuntu 20.04.
Step 1 – Install Required Packages For PostgreSQL Installation
First, you must run the system update with the command below:
sudo apt update
Then, install the required packages that are needed for your PostgreSQL 16 on Ubuntu 20.04:
sudo apt install dirmngr ca-certificates software-properties-common gnupg gnupg2 apt-transport-https curl wget -y
Step 2 – Import PostgreSQL GPG Key and Repository on Ubuntu
To install the latest PostgreSQL, first, create a file repository configuration with the command below:
sudo sh -c 'echo "deb [arch=amd64] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Then, import the GPG key by using the following wget command:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Next, update your system packages:
sudo apt update
Step 3 – Install PostgreSQL 16 on Ubuntu 20.04
At this point, use the command below to install the latest PostgreSQL on your server which is PostgreSQL 16:
sudo apt -y install postgresql
Step 4 – Install a Specific Version of PostgreSQL on Ubuntu
If you want to Install a Specific Version of PostgreSQL on Ubuntu 20.04, you can use the ‘postgresql-14’ or similar instead of ‘postgresql’ in the command. For example:
sudo apt -y install postgresql-14
Step 5 – Enable PostgreSQL Service
By default, PostgreSQL will be activated during the installation. To confirm this, run the following command:
sudo systemctl status postgresql
Output
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor pr>
Active: active (exited) since Tue 2023-09-19 09:31:02 CEST; 1min 16s ago
Main PID: 10694 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4620)
Memory: 0B
CGroup: /system.slice/postgresql.service
...
If your PostgreSQL service is not activated on Ubuntu 20.04, run the command below to enable it:
sudo systemctl enable postgresql --now
Step 6 – Access PostgreSQL Shell on Ubuntu
PostgreSQL uses a concept called roles to handle authentication and authorization.
During the PostgreSQL installation, Postgres is set up to use ident authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account.
If a role exists within Postgres, a Unix/Linux username with the same name is able to sign in as that role.
One way is to switch over to the Postgres account on your server by running the following command:
su postgres
Output
postgres@olivia:~$
You can access the Postgres shell on Ubuntu 20.04 by running the following command:
postgres@olivia:~$ psql
With this command, you will see that your shell prompt changes to:
Output
psql (16.0 (Ubuntu 16.0-1.pgdg20.04+1))
Type "help" for help.
postgres=#
To exit from the PostgreSQL shell on Ubuntu 20.04, run the following command:
postgres=# \q
With this command, you will be back to the Postgres Linux command prompt:
postgres@olivia:~$
You can type exit to return to the regular system user:
postgres@olivia:~$ exit
For more information, you can visit the PostgreSQL Documentation page.
Conclusion
At this point, you have learned to Install the latest PostgreSQL on Ubuntu 20.04 which is PostgreSQL 16. Also, if you plan to Install a Specific Version of PostgreSQL on Ubuntu 20.04, you need to specify it in the PostgreSQL installation command.
Hope you enjoy this guide on Install a Specific Version of PostgreSQL on Ubuntu 20.04. You may also interested in these articles:
Install MariaDB 10.11 on Ubuntu 20.04
Set up MySQL and Workbench on Ubuntu 20.04