Cannot install Git on Ubuntu 16.04 LTS

Some times our systems may not be up-to-date to receive an install so we can update with:

  • update package information:

    sudo apt-get update
    
  • upgrade packages on system and fix broken packages in the process:

    sudo apt-get -f dist-upgrade
    
  • only fix broken packages:

    sudo apt-get -f install
    

I had the same problem with liberror-perl when trying to install git. The other answers (sudo apt-get update && sudo apt-get dist-upgrade && apt-get -f install) didn't work for me.

From manually following the chain of dependency problems by trying to install each package directly, it looks like the problem is with perl-base:

$ sudo apt install liberror-perl
  liberror-perl : Depends: perl but it is not going to be installed

$ sudo apt install perl
  perl : Depends: perl-base (= 5.22.1-9) but 5.22.1-9ubuntu0.5 is to be installed

$ sudo apt install perl-base
  perl-base is already the newest version (5.22.1-9ubuntu0.5).

So the perl package depends on an outdated version of perl-base. I'm not sure how that was caused, but I suspect at one point a newer version was available, perhaps from a temporary apt source that was later removed on my system. I fixed the problem by downgrading perl-base to the version perl wants:

$ sudo apt install -f perl-base=5.22.1-9

After that, git installs properly. Just in case there was a newer perl-base version available, I tried upgrading it, but the above version was also the latest version:

$ sudo apt install perl-base=\*
perl-base is already the newest version (5.22.1-9).
Selected version '5.22.1-9' (Ubuntu:16.04/xenial [amd64]) for 'perl-base'

As far as I know this should not cause any problems, but YMMV.

Tags:

Git

Apt

16.04