Prevent ‘On Hold’ Packages from Showing Up During Upgrade – APT Guide

aptpackage-managementupgrade

I did sudo apt-mark hold nameofthepackage on 3 packages, but now I have an annoying remark when I upgrade with sudo apt-get upgrade :

Following packages have been holded : 
  package1 package2 package3
0 upgraded, 0 installed, 0 to remove and 3 non-updated.

(I'm sorry about the unexact output of the terminal, I'm using a french-version and I don't know exactly how to say this in english.)

Does it exist a way of "hiding" this ? I would like to have the usual 0 non-updated even when I hold packages. Thanks

Best Answer

Pin a package version using Apt Preferences

  1. Check current priority policy for my package, Example with virtualbox:

    $ apt-cache policy virtualbox
    virtualbox:
      Installed: 4.3.6-dfsg-1
      Candidate: 4.3.6-dfsg-2
      Version table:
         4.3.6-dfsg-2 0
            500 http://archive.ubuntu.com/ubuntu/ trusty/multiverse amd64 Packages
     *** 4.3.6-dfsg-1 0
            100 /var/lib/dpkg/status
    
  2. Create new file in /etc/apt/preferences.d/

    sudo vim /etc/apt/preferences.d/my_pin
    
  3. Add package you want (joker * can be used), with higher priority (default 0, max 1000, or even negative value like -1 to skip a version)

    Package: virtualbox*
    Pin: version 4.3.6-dfsg-1
    Pin-Priority: 500
    
  4. Check again:

    $ apt-cache policy virtualbox
    virtualbox:
      Installed: 4.3.6-dfsg-1
      Candidate: 4.3.6-dfsg-1
      Package pin: 4.3.6-dfsg-1
      Version table:
         4.3.6-dfsg-2 500
            500 http://archive.ubuntu.com/ubuntu/ trusty/multiverse amd64 Packages
     *** 4.3.6-dfsg-1 500
            100 /var/lib/dpkg/status
    
  5. No need to use hold, So sudo apt-mark unhold virtualbox but you could leave it as 2nd lock.

Now, if I check apt-get update, nothing is mentioned about about virtualbox (In held back packages listing).