Need to prevent a package from being installed [duplicate]
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).
- 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.
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:
-
download the required packages:
sudo apt-get --download-only install pkg-name
-
remove unwanted packages
sudo rm /var/cache/apt/archive/bad-pkg_*.deb
-
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