28

I have a package I do not want to be installed even if another needs it.

Is there any way to "blacklist" a package from being installed even as a dependency of another?

Can I overcome the fact that it is a dependency and still be able to upgrade my system?

I am thinking in particular about the messaging indicator from Unity. If I remove it and add Unity again for some reason, I dont want the applet installed again. How can I prevent it from being installed? (or the global menu, java versions removing my custom installed one, etc... you get the idea).

jdthood
  • 12,467
Bruno Pereira
  • 73,643

2 Answers2

39
  • Is there any way to "blacklist" a package from being installed even as a dependency of another?

To prevent apt from installing a package foo, add a stanza for that package to the file /etc/apt/preferences which looks like the following.

Package: foo
Pin: release *
Pin-Priority: -1

This will prevent apt from installing foo and will also prevent apt from installing anything that Depends on foo.

The next closest thing I can think of is to put a hold on foo at its current version which prevents foo from being upgraded (unless dpkg is given the --force-hold option or unless apt overrides the hold). To put a hold on package foo, do the following.

echo foo hold | sudo dpkg --set-selections
  • Can I overcome the fact that it is a dependency and still be able to upgrade my system?

You can install individual packages despite dependency violations using dpkg --force-depends. You won't be able to use apt to do this unless you apt-get source the package that Depends on foo and rebuild it without the dependency on foo.

jdthood
  • 12,467
  • Thanks, I guess this is as good as it gets... if I hold the package texlive-base and try to install latexmk I get The following packages have unmet dependencies: latexmk : Depends: texlive-latex-base but it is not going to be installed which is of course what I want. But if I hold latexmk and do sudo apt-get install latexmk I will get The following held packages will be changed: latexmk, as it turns out this actually removes the hold (well it least I get a warning). – Gerhard Burger Feb 04 '13 at 06:39
  • 1
    In an edit I just explained another way of preventing the installation of a package, using a stanza in /etc/apt/preferences. This has no effect on dpkg, of course. And it is still the case that if you blacklist a package you won't be able to use apt to install anything that Depends on it. – jdthood Feb 06 '13 at 19:24
  • 1
    In 16.04, I have only /etc/apt/preferences.d with nothing inside. What do I do? Or, should I create an /etc/apt/preferences file and it will read it? – Volomike Nov 24 '17 at 23:03
  • How does the blacklisting via the preferences file works? – mvorisek Jul 21 '19 at 16:16
  • Does not work if anoither package provides the package you had marked as hold. Example with sudo, it will install sudo-ldap , because it provides sudo... – Xorax Feb 20 '23 at 15:54
2

If a package needs (depends on) another package, then it should not work properly without it. If it can, it is a bug, it should be a recommend and not a depend.

To avoid to install a dependency:

  1. download the required packages:

    sudo apt-get --download-only install pkg-name
    
  2. remove unwanted packages

    sudo rm /var/cache/apt/archive/bad-pkg_*.deb
    
  3. install all other packages

    sudo apt-get --no-download --ignore-missing install pkg-name
    

On the other side, to install a package without recommends:

sudo apt-get --no-install-recommends install pkg-name
enzotib
  • 93,831