Preventing specific packages from getting installed in Debian

Solution 1:

Putting a package on hold does not work (very well) to achieve this. It does not cover all tools in a satisfactory manner. For example aptitude on command-line completely ignores the previous invocation of aptitude hold somepackage, installing a package also installs the dependencies even if they are on hold.

The best way in my opinion is to create a fake package (named for example "unwanted-pkg") that conflicts with all the packages that you don't want and to install it (with dpkg -i). And then you put this package on hold to avoid its removal.

You can use a tool like "equivs" to create the fake package easily. See equivs-control and equivs-build. A conflicts field look like this:

Conflicts: xserver-xorg-video-2, xserver-xorg-core

You can conflict with the low-level dependencies common to all unwanted packages to avoid listing each individual package (or use virtual package like xserver-xorg-video-2).

Note that pinning does not work to solve this problem. If you do aptitude install xorg it will install many xserver-xorg-* packages despite the negative pinning. BTW, for the pinning to be recognized by apt (check with apt-cache policy <package>) you have to use a syntax like this one:

$ cat /etc/apt/preferences
Package: xserver-xorg-video-vga
Pin: version *
Pin-Priority: -100
$ LANG=C apt-cache policy xserver-xorg-video-vga
xserver-xorg-video-vga:
  Installed: (none)
  Candidate: 1:4.1.0-8
  Package pin: 1:4.1.0-8
  Version table:
     1:4.1.0-8 -100
        500 http://localhost lenny/main Packages

Using a regexp in the Package field does not work (except for "*" alone, in which case you have some other requirements in the Pin field).

Solution 2:

http://www.debian.org/doc/FAQ/ch-pkg_basics.en.html

See section 7.12, "How do I put a package on hold?"

If you 'hold' a currently uninstalled package, it will never be installed.

Solution 3:

You can use apt pinning to prevent certain packages from being installed. Try putting this in /etc/apt/preferences:

Package: xserver-xorg*
Pin-Priority: -100

Should prevent installing all xserver-xorg* packages.