34

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?

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Lucas Perry
  • 361
  • 1
  • 4
  • 7
  • 1
    I faced same problem, following tutorial resolved my problem https://computingforgeeks.com/install-postgresql-11-on-ubuntu-linux/ – Archana Mar 09 '21 at 09:06
  • 1
    Ergghhh... SO discourages the use of screenshots in Q&A in favor of raw text: https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors – Sarah Messer Feb 28 '23 at 21:24

5 Answers5

45
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
Jithin Pavithran
  • 1,250
  • 2
  • 16
  • 41
Tarique
  • 4,017
  • 1
  • 26
  • 25
  • 1
    After `sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/lsb_release -cs-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'` I get: E: Malformed entry 1 in list file /etc/apt/sources.list.d/pgdg.list (Component) E: The list of sources could not be read. – Asmoox Nov 25 '19 at 10:49
  • @Asmox, the proper command is `sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'`. You can delete the broken record inside `/etc/apt/sources.list.d/pgdg.list` and then run the command. – Mario Tacke May 23 '20 at 01:51
18

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".

Maciej Sz
  • 11,151
  • 7
  • 40
  • 56
  • 3
    So I have this: `apt-cache search postgresql | grep client` the only relevant thing that shows up `postgresql-client-10`...so maybe version 11 is not supported on my ubuntu version? how do I find out? –  Aug 08 '19 at 23:45
9

It should work.

$ sudo apt-get install postgresql postgresql-client
Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
Mr.Леон
  • 144
  • 1
  • 6
2

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

Ramesh Ponnusamy
  • 1,553
  • 11
  • 22
0

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