The Global Development Group of PostgreSQL is maintaining their own apt repo. Instead of using the default and outdated PostgreSQL packages that ship with Ubuntu 18.04 we can always get the latest version by adding this repository. This way we are also flexible and can specify which version of PostgreSQL we want to install.
To make sure and validate we receive the PostgreSQL packages from the real owner we will add the following apt key to our keyring. This way we make sure we don't get injected bad packages.
sudo apt install curl ca-certificates gnupg curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Depending on your distribution and version we need to add a different codename to the sources list. Thanks to "lsb_release -c" we don't need to manually specifiy it, we can simply get the distribution with that command.
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
To reflect the changes we just did to the sources list we need to simply update the packages and afterwards install the desired PostgreSQL version.
apt update apt install postgresql-11