Monday, June 4, 2018

Install PostgreSQL 10 on Ubuntu 16.04 LTS

Install PostgreSQL 10 on Ubuntu 16.04 LTS

I was facing issues to install PostgreSQL 10 on Ubuntu 16.04 LTS, so I documented it, so others can save time. Note that technical platform are very dynamic, might change over the period.

The PostgreSQL Global Development Group (PGDG) maintains an APT repository of PostgreSQL packages for Debian and Ubuntu located at http://apt.postgresql.org/pub/repos/apt/. Their aim to building PostgreSQL server packages as well as extensions and modules packages on several Debian/Ubuntu releases for all PostgreSQL versions supported.

I am using their repository to install PostgreSQL 10. Note that default apt repository fro Ubuntu 16.04 LTS is PostgreSQL 9.5.

Step 1:

Create /etc/apt/sources.list.d/pgdg.list. The distributions are called codename-pgdg. For Ubuntu 16.04 LTS the code name is xenial. Two way you can do that; first one will do for any version as it is determinig the code name of the operating system.

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

or for Ubuntu 16.04 LTS

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/xenial-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

or you can manually add by:

$ sudo nano /etc/apt/sources.list.d/pgdg.list

Add

deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main

Press Ctrl X, Y to save and close.

Step 2:

Import the repository key from https://www.postgresql.org/media/keys/ACCC4CF8.asc, update the package lists, and start installing packages:

$ sudo apt-get install wget ca-certificates

$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install postgresql-10

Step 3

Connect to postgres and create password for 'postgres' user.

$ sudo su - postgres

$ psql

\password postgres

enter your desired password twice. exit from psql.

# \q

All done.









No comments:

Post a Comment