Can I configure Ubuntu to never install a specific package even if it is required by another package I install?
-
You cannot install a package without its dependencies, unless you want to break your system. – enzotib Nov 05 '11 at 22:05
-
2@enzotib, first of all you're wrong: package dependencies can be redundant. there are numerous examples, or you can have installed an equivalent of a required package another way (for example I have openjdk-6 installed as it is required by all the java applications in the repos, but I never actually use openjdk-6, I set up everything to use openjdk-7 or Oracle JDK 7 instead). And the second thing - I didn't say I want the dependant package to be installed - it can just throw an error in this case, I just want to make sure a particular package is never installed anyway. – Ivan Nov 05 '11 at 22:29
-
There is a [similar question](http://askubuntu.com/q/59083). – Nimmermehr Nov 08 '11 at 15:38
3 Answers
As in Debian we can use apt-pinning for version and installation control in Ubuntu too.
To block the installation of a given package we may put the following lines in /etc/apt/preferences
Package: <nameofpackage>
Pin: origin ""
Pin-Priority: -1
By giving a negative priority for this pin we will block the installation of <nameofpackage> from not further specified origin, i.e. our local repository. Of course we can use apt-pinning to pin a certain package version or specific origin.
Before you proceed it is strongly recommended to read the documentation given above and the manpage from apt_preferences because errors in these files are not checked by apt and if they occur may break your package management.
For an alternative, and to prevent updating of a given package see:
- 140,996
- 54
- 308
- 426
-
Do you know if this could work in Ubuntu 12.04? [Another question](http://askubuntu.com/q/258916/62483) is reporting that maybe it doesn't work. – Lucio Feb 20 '13 at 19:27
-
1
-
3In the `Package:`-line, you can list multiple packages separated with spaces, like this: Package: metacity metacity-common libmetacity-private0a. (Seems like patterns like Package: metacity* are also possible) – Volker Siegel Aug 22 '14 at 02:46
-
16In Ubuntu 16.04 `Pin: origin ""` didn't work for me, but `Pin: release *` did. – barbaz May 07 '17 at 15:00
-
5In Ubuntu 20.04, this seems to be the only way to prevent a package to be installed. The `apt-mark hold` solution described elsewhere does not work exactly as expected: sometimes it will work _once_ (i.e. for the _next_ upgrade), but then the 'hold' gets 'released' and `apt` will try to install it again... the only thing that seems to consistently work is adding files inside `/etc/apt/preferences.d` with `Pin: release *`. It's worth reading the man page: there are serious limitations in the filename; and you can use multiple packages in the same configuration file as well as use wildcards. – Gwyneth Llewelyn Oct 15 '20 at 14:49
-
-
This does work for `apt`, but does not seem to affect the `snap` unfortunately (which is the default installer on 20.04 if I understand well). – nocibambi Sep 09 '21 at 19:51
-
@nocibambi: for snaps see: https://askubuntu.com/questions/1131182/how-can-i-disable-automatic-update-for-a-single-snap-in-ubuntu – Takkat Sep 11 '21 at 16:32
I have a package that keeps sneaking back in and breaking git
sudo apt-mark hold libgnutls-deb0-28
should prevent that package from being installed
- 281
- 5
- 8
-
This is not a reliable solution, especially when you have to upgrade your distro. The good solution is already provided: https://askubuntu.com/a/76075/93706 – Gilles Quénot Aug 28 '23 at 15:30
In debian you can block a package, and that package wont upgrade anymore
# echo name_of_package hold | dpkg --set-selections
but I'm not sure that you can forbid
-
1I just tried it on Ubuntu 15.10 (wily) and it didn't block the package; just gave me a warning `package not in database` – Brent Baccala Aug 22 '16 at 20:55
-
This is not a reliable solution, especially when you have to upgrade your distro. The good solution is already provided: https://askubuntu.com/a/76075/93706 – Gilles Quénot Aug 28 '23 at 15:29