7

Hi I recently upgraded the OS from Ubuntu18.04 to Ubuntu20.04. Now I notice that when I do sudo apt-get upgrade, I have packages kept back:

The following packages have been kept back:
  build-essential cpp g++ gcc gfortran liblapack-dev liblapack3
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.

I tried the methods mentioned here. To resolve this I tried

sudo apt-get dist-upgrade

but the output is the same as before.

I also tried sudo aptitude full-upgrade and the solution is also to keep the packages at their current version. The output is the following:

The following NEW packages will be installed:
  cpp-9{ab} g++-9{ab} gcc-9{ab} gfortran-9{ab} libasan5{ab} libgcc-9-dev{ab} libgfortran-9-dev{ab} libgfortran5{ab} libstdc++-9-dev{ab} 
  libubsan1{ab} 
The following packages will be upgraded:
  build-essential cpp g++ gcc gfortran liblapack-dev liblapack3 
7 packages upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 44.5 MB of archives. After unpacking 170 MB will be used.
The following packages have unmet dependencies:
 cpp-9 : Depends: gcc-9-base (= 9.3.0-17ubuntu1~20.04) but 9.4.0-1ubuntu1~18.04 is installed
 libgfortran-9-dev : Depends: gcc-9-base (= 9.3.0-17ubuntu1~20.04) but 9.4.0-1ubuntu1~18.04 is installed
 libasan5 : Depends: gcc-9-base (= 9.3.0-17ubuntu1~20.04) but 9.4.0-1ubuntu1~18.04 is installed
 libstdc++-9-dev : Depends: gcc-9-base (= 9.3.0-17ubuntu1~20.04) but 9.4.0-1ubuntu1~18.04 is installed
 libubsan1 : Depends: gcc-10-base (= 10.2.0-5ubuntu1~20.04) but 10.3.0-1ubuntu1~18.04~1 is installed
 g++-9 : Depends: gcc-9-base (= 9.3.0-17ubuntu1~20.04) but 9.4.0-1ubuntu1~18.04 is installed
 libgfortran5 : Depends: gcc-10-base (= 10.2.0-5ubuntu1~20.04) but 10.3.0-1ubuntu1~18.04~1 is installed
 gcc-9 : Depends: gcc-9-base (= 9.3.0-17ubuntu1~20.04) but 9.4.0-1ubuntu1~18.04 is installed
 gfortran-9 : Depends: gcc-9-base (= 9.3.0-17ubuntu1~20.04) but 9.4.0-1ubuntu1~18.04 is installed
 libgcc-9-dev : Depends: gcc-9-base (= 9.3.0-17ubuntu1~20.04) but 9.4.0-1ubuntu1~18.04 is installed
The following actions will resolve these dependencies:

      Keep the following packages at their current version:
1)      build-essential [12.4ubuntu1 (now)]                
2)      cpp [4:7.4.0-1ubuntu2.3 (now)]                     
3)      cpp-9 [Not Installed]                              
4)      g++ [4:7.4.0-1ubuntu2.3 (now)]                     
5)      g++-9 [Not Installed]                              
6)      gcc [4:7.4.0-1ubuntu2.3 (now)]                     
7)      gcc-9 [Not Installed]                              
8)      gfortran [4:7.4.0-1ubuntu2.3 (now)]                
9)      gfortran-9 [Not Installed]                         
10)     libasan5 [Not Installed]                           
11)     libgcc-9-dev [Not Installed]                       
12)     libgfortran-9-dev [Not Installed]                  
13)     libgfortran5 [Not Installed]                       
14)     liblapack-dev [3.7.1-4ubuntu1 (now)]               
15)     liblapack3 [3.7.1-4ubuntu1 (now)]                  
16)     libstdc++-9-dev [Not Installed]                    
17)     libubsan1 [Not Installed]      

           

Can someone give me some suggestions? Thanks!

3
  • 1
    Take a look at gcc-9-base as an example: No Ubuntu repositories have version 9.4.0-1ubuntu1~18.04, so that's from a non-Ubuntu source. Whatever source that is, you should have uninstalled those packages before upgrading.
    – user535733
    Jun 5, 2021 at 21:47
  • 1
    Hi@user535733 Thanks for the valuable insight. I remove gcc-9-base and gcc-10-base and manually install them. Now the issue has been solved.
    – PLNewbie
    Jun 5, 2021 at 22:42
  • 1
    Best practice is to keep track of packages that you install from non-Ubuntu sources. Uninstall those packages before you release upgrade -- return your system to as close to stock condition as possible to avoid hiccups like this. After the release-upgrade is completely successful, you can decide if you still need the non-Ubuntu packages or not, and re-install those that you want.
    – user535733
    Jun 5, 2021 at 23:42

4 Answers 4

10

It turns out I need to sudo apt-get remove gcc-9-base and then sudo apt-get install gcc-9-base. Same thing needs to done for gcc-10-base as well.

2

I also had a similar error, with the gcc-9-base package. What worked for me was:

  • Check for available versions. Like this:

    $ apt-cache madison gcc-9-base
    

The result may look something like this:

gcc-9-base | 9.3.0-17ubuntu1~20.04 | http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
gcc-9-base | 9.3.0-17ubuntu1~20.04 | http://archive.ubuntu.com/ubuntu focal-security/main amd64 Packages
gcc-9-base | 9.3.0-10ubuntu2 | http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
  • Choose the needed version, in this case 9.3.0-17ubuntu1~20.04, and install like this:

    $ sudo apt-get install gcc-9-base=9.3.0-17ubuntu1~20.04
    

apt-get should manage to fix your broken packages now.

P.S.: I know this question is a bit old now, but here's the solution for anyone that has had a similar problem.

0

PLNewbie's answer works: apt remove and install [packagename] resolves issues with packages "kept back."

apt install [*packagename*] without first removing [packagename] is also working so far. e.g.

sudo apt install nftables

This has resolved a handful of packages "kept back" since upgrading to 22.04[0]. It appears update or overwrite the previous version of same:

sudo apt list -ia nftables

Listing... Done 
nftables/jammy-updates,now 1.0.2-1ubuntu3 amd64
[installed] nftables/jammy 1.0.2-1ubuntu2 amd64

[0] via Software Updater prompt and without explicit dist-upgrade by me.

1
  • This method still has unresolved issues. I've seen a few packages recur to "kept back" after previous explicit installs without first removal. The issue has occurred with ~20 packages. It's occurring less frequently. and my manual intervention "encourages" me to pay more attention to what apt and snap are doing. I'm not yet ready for sudo apt-get dist-upgrade or other higher-level / coarser-grained approaches.
    – smcnally
    Oct 14, 2022 at 22:00
-1

For a little more explanation, when a package is "kept back", that means that there is a new version of it available, but installing that new version would involve removing some packages or installing other new ones, and the upgrade command won't do that automatically.

You want to instead use the install command; e. g.:

sudo apt-get install build-essential cpp g++ gcc gfortran liblapack-dev liblapack3

This will also install (or remove) any other packages that are necessary to satisfy those upgrades. Read over the output from this carefully before you accept it; if the reason a package is kept back is because the new version conflicts with another package you have installed, apt may want to resolve the problem by removing that package, so double-check anything it says it's going to remove to make sure that's acceptable.

2
  • Thanks for the response! I actually tried this earlier but it still simply keep back the packages as using sudo apt-get dist-upgrade.
    – PLNewbie
    Jun 5, 2021 at 23:02
  • If it still keeps the packages back, that can means that the packages you're trying to upgrade conflict with each other. That can be a real pain to diagnose, but sometimes installing them one at a time until you run into a package that is trying to remove one of the others.
    – Minneyar
    Jun 5, 2021 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .