Debian / Ubuntu Linux apt-get: Blacklist a Package From Installing

by on September 29, 2012 · 3 comments· LAST UPDATED September 29, 2012

in

I've build my own lighttpd .deb package and I do not want to upgrade it using the apt-get command. Also, I do not want to upgrade a few more packages such as php5-cgi, httpd and so on. How do I blacklist a package or packages so that when I run apt-get upgrade, it will ignore blacklisted packages and install the rest of updates under Debian or Ubuntu Linux server system?

Tutorial details
DifficultyIntermediate (rss)
Root privilegesYes
Requirementsdpkg
Estimated completion timeN/A

You need use the dpkg command - a tool to install, build, remove and manage Debian packages. Each package under Debian or Ubuntu Linux has the following selection stats:

  1. install - The package is selected for installation.
  2. hold - A package marked to be on hold is not handled by dpkg, unless forced to do that with option --force-hold.
  3. deinstall - The package is selected for deinstallation (i.e. we want to remove all files, except configuration files).
  4. purge - The package is selected to be purged (i.e. we want to remove everything from system directories, even configuration files).

Option #1: dpkg command syntax

To blacklist a Debian / Ubuntu package use the following command:

 
echo "packageName hold" | dpkg --set-selections
echo "lighttpd hold" | dpkg --set-selections
 

To remove package hold and install/upgrade again:

 
echo "packageName install” | dpkg --set-selections
echo "lighttpd install” | dpkg --set-selections
 

Option #2: /etc/apt/apt.conf.d/01autoremove

Another option is to edit a file called /etc/apt/apt.conf.d/01autoremove, enter:
# vi /etc/apt/apt.conf.d/01autoremove
Sample outputs:

APT
{
  NeverAutoRemove
  {
        "^firmware-linux.*";
        "^linux-firmware$";
        "^linux-image.*";
        "^kfreebsd-image.*";
        "^linux-restricted-modules.*";
        "^linux-ubuntu-modules-.*";
  };
  Never-MarkAuto-Sections
  {
        "metapackages";
        "restricted/metapackages";
        "universe/metapackages";
        "multiverse/metapackages";
        "oldlibs";
        "restricted/oldlibs";
        "universe/oldlibs";
        "multiverse/oldlibs";
  };
};

Move cursor at the the bottom of the section called "Never-MarkAuto-Sections" and append and entry to the section to block grub I entered "php5-cgi*":

  Never-MarkAuto-Sections
  {
        "metapackages";
        "restricted/metapackages";
        "universe/metapackages";
        "multiverse/metapackages";
        "oldlibs";
        "restricted/oldlibs";
        "universe/oldlibs";
        "multiverse/oldlibs";
        "php5-cgi*";
  };

Save and close the file.

A note about RHEL / CentOS / SL / Fedora Linux users

You need to edit a file called name.repo see, how to blacklist a package under RHEL / CentOS for more information.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 Stephan Hughson September 30, 2012 at 8:26 am

There’s another way to do this under Ubuntu and Debian which I like as I’m quite lazy.

You have to install a package called wajig, but it’s small and doesn’t interfere.

sudo apt-get install wajig

and then can just do :

sudo wajig hold packagename

wajig can do lots of other things too, but I haven’t investigated them yet.

Reply

2 Ritesh Raj Sarraf September 30, 2012 at 7:15 pm

Another option is to use equivs and add all those packages that you never want to see installed into its Conflicts: list.

Reply

3 Jens Stomber October 8, 2012 at 9:35 pm

Hi,

I suggest to use apt pinning to blacklist packages or set certain versions of a package on hold.

wiki.debian.org
debian-handbook.info

Reply

Leave a Comment

Tagged as: , , , , , ,

Previous Faq:

Next Faq: