I've got several Debian servers, and I want to ensure that an X server never gets installed on them. Sometimes when I'm installing a package, it has dependencies that include X. Is there any good way to make sure that the X server never gets installed? I'd prefer that the X11 libraries not get installed either, since X forwarding should never be enabled.
4 Answers
The tip of Raphael Herzog is already pretty good but there is one problem with the solution. aptitude doesnt care about any holds so the conflicting fake-package is removed anyway. To prevent this, one can add a removal script in the package control file of the fake-package (see https://stackoverflow.com/questions/40800577/how-to-forbid-apt-to-remove-certain-package-during-dist-upgrade). This script (name: my-prerm) fails if the user does not explicitly confirms that he want to remove the conflicting fake-package, which causes the removal of the package to be aborted.
#!/bin/sh -e
if [ "$1" != remove ]; then
exit 0
fi
echo "are you sure about removing your essential package? (y/N)"
read i
if [ "x$i" = "xy" ]; then
exit 0
fi
false
The control file should contain an entry: Prerm: my-prerm
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).
-
I think you should file a bug report on aptitude. Either "aptitude hold" is not properly setting the selection for the package, or "aptitude install" is not honoring the selection.– SparrJun 3, 2009 at 20:00
-
There are lots of (old) bugreports open on this topic already, unfortunately the maintainer is busy and can only deal with so many bugs each month. See bugs.debian.org/aptitude and search "hold". Jun 5, 2009 at 7:40
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.
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.
-
-
When did wildcards start working in package names in apt_preferences?– derobertJun 3, 2009 at 5:13