89

I am writing this because I am very confused about installing PostgreSQL 9.3 on my Ubuntu 14.04. First I need it for my Python/Django development, and I ran into the problem when I tried to install it. Now I have this error and it is driving me crazy:

The following packages have unmet dependencies:
postgresql-9.3 : Depends: postgresql-client-9.3 but it is not going to be installed
                 Depends: postgresql-common (>= 142~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

I have found some solutions online (How do I resolve unmet dependencies after adding a PPA?), and I did everything to the Preventive Measures part, because I have had some broken packages problem, and again after I had this error show to me again.

The second thing I have followed the official PostgreSQL installing tutorial (http://www.postgresql.org/download/linux/ubuntu/), and I have had duplicated repositories, but I have deleted them and I have added a fresh one but still this error.

copser
  • 1,376

6 Answers6

72

You can install the package using.

make sure the repo sources are up to date

sudo apt-get update

To Install the package.

sudo apt-get install packagename

Once the package determines that you have some missing dependencies, run the following command to fix broken or missing dependencies.

sudo apt-get install -f

Above command will only download the missing dependencies if you have already installed the package.

Tim
  • 32,861
  • 27
  • 118
  • 178
64

I know I'm a bit late, but none of the above solutions worked for me. What really solved my problem was to use aptitude instead of apt-get. aptitude will suggest resolutions to the problem.

Simply run these:

sudo apt-get install aptitude

sudo aptitude install <package-name>

aptitude will suggest dependencies resolution for you e.g:

The following actions will resolve these dependencies:

Keep the following packages at their current version:

  1. libyaml-dev [Not Installed]                        
    
    

Accept this solution? [Y/n/q/? (n)

The following actions will resolve these dependencies:

Downgrade the following packages:

  1. libyaml-0-2 [0.1.4-3ubuntu3.1 (now) -&gt; 0.1.4-3ubuntu3 (trusty)]
    
    

Accept this solution? [Y/n/q/?] (Y)

as discussed in this post.

Gabriel Ziegler
  • 1,486
  • 2
  • 16
  • 23
  • 5
    This worked for me while the other answers didn't. Thanks! – aniztar Jun 18 '20 at 08:55
  • 3
    The crucial thing for me was that aptitude was willing to suggest downgrading packages whereas apt was not. This offered me the solution of removing a third-party package from a PPA and resetting it to the stock Ubuntu version which fixed all my dependency issues. – Migwell May 12 '21 at 11:24
  • This worked for me while the others did not. Just wondering now why this isn't the standard tool. It's so much more user friendly than just saying "I can't" without a reasoning why. – CodeMonkey Nov 08 '22 at 09:02
  • That's a life saver :) – Gogol Dec 22 '22 at 08:48
  • genius , Thank you – Ahmed Shehatah Dec 22 '22 at 20:15
14

Sometimes the dependencies that need fixing are unrelated to the program you are trying to install. In my case it was giving off this error:

The following have unmet dependecies

shashlik : Depends: libc6-i386 but it is not going to be installed

Depends: lib32gcc1 but it is not going to be installed

Depends: lib32z1 but it is not going to be installed

It turned out that I had tried to install a program called "Shashlik" and the installation had failed. So I ran the code:

sudo apt-get --purge remove shashlik

And then I ran:

sudo apt install autoconf

This seemed to fix the error as my program then installed. I am not sure how much the second command helped but I put it there in case it was necessary for the solution to work.

8

Let me share with other people my experience with installing postgresql-9.3. First of all I have been struggling with this for about 4/5 days, and I finally manage to do it.

All went wrong with these nasty errors I have shared in my first post, as I have tried to google it and discover that people have more less the same error, or struggling to solve a similar one.

Long story short, you have a very nice answer here how to resolve unmet packages:

How do I resolve unmet dependencies after adding a PPA?

My mistake was that I have made duplicated repository, and the answer in this link solved that, this command sudo apt-get install -f just made another error, you must do this manually, at least I did it (read to the section Preventive Measures, but you could read to the end, it is an imba post).

Second I manage to google this post from official PostgreSQL page http://www.postgresql.org/message-id/20140327084212.GA12703@msgid.df7cb.de (this is the error people usually have when they are struggling with installation of postgresql), this led me to
https://wiki.postgresql.org/wiki/Apt, this is the proper way for adding PostgreSQL Packages to your system, just read it and do it step by step.

Third step are series of commands provided in the @vembutech post:

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install postgresql-9.3 postgresql-contrib-9.3
copser
  • 1,376
6

First of all you've to find the package that is broken. Let's say you're getting following error,

The following packages have unmet dependencies:
 libpython3.9 : Depends: libpython3.9-stdlib (= 3.9.5-3~20.04.1) but 3.9.4-1+bionic1 is to be installed

You've to manually remove the files of broken package.

To get the list of the files you can run

sudo ls –l /var/lib/dpkg/info | grep -i libpython3.9-dev

Replace libpython3.9-dev with your own package name.

Output

libpython3.9-dev:amd64.list
libpython3.9-dev:amd64.md5sums

Now, you can to discard these files.

sudo rm /var/lib/dpkg/info/python3.9-dev*

Perform the same operations for the rest of packages.

Once it's done, you can run

sudo apt --fix-broken install

This time the above command should work fine.

Krishna
  • 338
3

Try by installing the with below command.

sudo apt-get install postgresql-common=151.pgdg12.4+1

sudo apt-get install postgresql-9.3 postgresql-contrib-9.3
Tim
  • 32,861
  • 27
  • 118
  • 178
BDRSuite
  • 3,156
  • 1
  • 12
  • 11