How do I install the latest version of PostgreSQL on Ubuntu 16.04?
When I created my current Linode I believe I installed Postgres using the following
https://www.linode.com/docs/databases/postgresql/how-to-install-postgresql-on-ubuntu-16-04/
I am on version 9.5.14
$ psql -V
psql (PostgreSQL) 9.5.14
========================================
I wish to upgrade to the current version I believe 11.1 but not to sure how to do this
1 Reply
The way that apt-get works in this case is that by default it pulls down the version of postgres that is guaranteed to work throughout the lifetime of your distribution. For Ubuntu 16.04 the default version of postgres is 9.5
Here is an article from postgres about how to install a more recent version:
https://www.postgresql.org/download/linux/ubuntu/
Essentially you will need to add a file in your /etc/apt/sources.list.d
directory that points to the posgtgres repos.
You can add the file
touch /etc/apt/sources.list.d/pgdg.list
and then edit it with your favorite text editor to add the following line:
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
Or here is a handy one line command to create and edit the file:
echo "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
Once that is done you will need to import the repo signing key and update your package lists:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update
When this completes you can run the following command to the version you are looking for:
sudo apt-get install postgresql-11
If you already have data in your db that you need in your newly updated database, you may also want to look into using pg_upgrade. Since major version changes can sometimes change the underlying postgres system tables, this can help to make sure you don't have to dump and reload your data.