104

Recently, I needed to get a list of packages that were installed on my Ubuntu system which were also put on hold for upgrade.

The 'hold' status for a package means that when the operating system is upgraded, the installer will not upgrade these packages either, unless explicitly stated in the options.

I am looking for a command-line solution but understand this may be possible from the GUI as well.

Anwar
  • 76,649
pmagunia
  • 1,522

5 Answers5

129

You can use apt-mark:

apt-mark showhold

this will show the packages that are kept in "hold" state so that the pacakge manager won't auto upgrade the packages.

From man apt-mark:

showhold
           showhold is used to print a list of packages on hold
heemayl
  • 91,753
  • 12
    Shows nothing but system is complaining about held packages. Must be more fundamental way. – mathtick Mar 25 '20 at 18:54
  • 2
    just upgraded to, then did a fresh install of xubuntu 20.04.1 desktop. I have the same experience --> " lib32z1 : Depends: libc6-i386 (>= 2.4) but it is not going to be installed E: Unable to correct problems, you have held broken packages." apt-mark showhold returns null – BISI Nov 05 '20 at 00:46
25

Use dpkg

dpkg -l | grep "^hi"

The -l means to list all packages which are then piped into grep.

The regular expression "^hi" means to search for all lines that begin with "hi" which are initials for "hold" and "installed".

By default, dpkg -l will list the status, package name, version, architecture, and a short description.

pmagunia
  • 1,522
  • 1
    This method works on debian systems regardless of the higher level package wrapper being used, thus it is more general. – uDude Jul 30 '19 at 14:01
  • 3
    for inspecting my system when something fishy is going on dpkg -l | grep --invert-match "^ii" helped me every now and then. - this lists all packages which are not just installed as they should be. – DJCrashdummy Feb 20 '21 at 05:19
  • @DJCrashdummy: I, too, did find lots of packages with status ri instead of ii. Every one of those was fixed with sudo apt install --reinstall package-name. Do you know what might cause these problems? – Mikko Rantalainen Jul 14 '21 at 14:00
  • 1
    @MikkoRantalainen at the top of the output of dpkg -l you've got a little explanation of the output... ii means the package is currently installed (2nd letter) and it should stay installed (1st letter). ri means that the package is currently installed (2nd letter) and should be removed/uninstalled (1st letter) but keep configuration. - so i'm not sure what you are "fixing". || real errors would be indicated through a 3rd letter or i would also investigate a little bit more if the 2nd letter is for instance a F or a H. – DJCrashdummy Jul 15 '21 at 10:23
  • Why would a package enter state ri when I haven't requested the package to be removed? – Mikko Rantalainen Jul 15 '21 at 16:41
  • @MikkoRantalainen well... this finally exceeds the scope of comments to a more or less unrelated question/answer (perhaps a separate question with more detailed information would be reasonable), but i guess dependencies...? :-D – DJCrashdummy Jul 16 '21 at 10:00
  • ...this is also a reason why most of the time average users should use Synaptic, apt or aptitude instead of dpkg, if not a completely simple package manager resp. app store by their distribution. – DJCrashdummy Jul 16 '21 at 10:02
  • I forked the new question to https://askubuntu.com/q/1352226/50254 – Mikko Rantalainen Jul 16 '21 at 12:32
7

as an alternative you can also use dpkg --get-selections:

dpkg --get-selections | grep "\<hold$"

dpkg --get-selections lists the status of all installed packages and grep "\<hold$" only shows lines which end with the word "hold".

perhaps also interesting, if you are looking for irregularities - especially if the above shows nothing (useful), would be

dpkg --get-selections | grep --invert-match "\<install$"

this shows all lines/packages which are not just installed.

DJCrashdummy
  • 1,911
2

In apt-mark versions > 2.4 you have to use the following command:

apt-mark showhold

Also it is an old tool aptitude does a fine job on the command line and you can easily surf through the hold packages:

aptitude

Type u to update packages and then press g and you will see the held back packages.

abu_bua
  • 10,783
1

And to unhold all held packages, use

sudo apt-mark unhold $(apt-mark showhold)

xpt
  • 1,045
  • 1
    This doesn't answer the question. – Paddy Landau Mar 03 '23 at 16:41
  • 3
    I landed here because I was searching for how to unhold packages. Feel free to delete my answer and those people landed here for the same reason will still be at lost. This is not to answer the question as the top one has already done so. Moreover, the reason people need to find out the held packages is most probably to unhold them. My answer just save them to find the how to for the next step. – xpt Mar 03 '23 at 22:24
  • This should be a comment, not an answer. – sondra.kinsey Aug 15 '23 at 13:14