To develop great applications you need a great database manager. So, that is why in this post I will teach you how to install PostgreSQL 12 on Ubuntu 18.04.
PostgreSQL is one of the most advanced and modern relational database managers out there. It is always shown as the immediate competitor of MySQL and MariaDB in the segment of open source and community database managers.
One of the main advantages of using PostgreSQL is that it has extensive documentation and supports powerful features. All this in an open-source and free application.
And recently version 12 has been released. If you want to know more about it read our post about it.
So, let us start to work.
Install PostgreSQL 12 on Ubuntu 18.04
The best way to install PostgreSQL 12 on Ubuntu 18.04 is to use the repository that PostgreSQL developers make available to us.
In addition, it is a very secure repository with good support for Ubuntu.
So, install some necessary packages.
:~$ sudo apt install curl ca-certificates gnupg
Then, download and add the GPG key from the repository to further secure the installation.
:~$ curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Now, we have to add the PostgreSQL repository. To do this, create a source file in
/etc/apt/sources.list.d/ and add the following:
:~$ sudo nano /etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
Then, save the changes and close the editor.
Finally, install PostgreSQL 12 on Ubuntu 18.04 using the following command.
:~$ sudo apt update && sudo apt install postgresql-12
Now, let’s make sure everything works.
Testing the installation
Of course, there are many ways to test whether everything went well. However, so as not to lengthen the post unnecessarily, we’ll just open the PostgreSQL console and run a command.
First, we have to change to the postgres user. This user is created during installation.
:~$ sudo -i -u postgres
This user has access to the PostgreSQL console. So just access it.
And inside we’ll be able to execute whatever commands we want. In this case, we will be satisfied with simply listing the example databases.
This way when showing the existing databases, we will know that everything has worked.
That is it. So, you can now use the latest version of PostgreSQL on Ubuntu 18.04.