Cannot install postgres on Ubuntu (E: Unable to locate package postgresql)

110.2k Views Asked by At

So I'm having this problem where for some reason I can't install any package on my ubuntu system. I'm currently on Ubuntu 16.10.

terminal install logs

terminal install logs


Update:

I've done entered those commands and got this.

after update and apt-cache

after update and apt-cache

What should I do now?

5

There are 5 best solutions below

1
On

First do

sudo apt-get update

You should get no errors upon updating. In case you do, then you might have issues with your firewall, or something blocking you from updating repositories. Check the output carefully.

And then search for the correct (exact!) package name using this command:

apt-cache search postgresql

As a last resort you could add external 3rd Party repository as described in this answer. Just remember to use your distribution name instead of "xenial".

0
On

If you are getting (E: Unable to locate package postgresql-12) while migrating following step may helps you:

sudo apt-get -y install bash-completion wget
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | 
sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-12 postgresql-client-12
sudo systemctl status postgresql

ref:install postgres12 in ubuntu-18.04

2
On
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

After installing the PostgreSQL database server, by default, it creates a user ‘postgres’ with role ‘postgres’. Also creates a system account with the same name ‘postgres’. So to connect to Postgres server, log in to your system as user postgres and connect database.

sudo su - postgres
psql
0
On

Following Commands worked for me: sudo apt-get install wget ca-certificates

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ lsb_release -cs-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt install postgresql-11 libpq-dev
0
On

It's Working

It should work.

$ sudo apt-get install postgresql postgresql-client