559

Because of bug #693758 I'd like to prevent apt-get upgrade and Update Manager from updating the "libgtk2.0-0" package.

How can this be achieved?

Braiam
  • 67,791
  • 32
  • 179
  • 269
Ivan
  • 57,065
  • @hhlp: But this question is asking about a package that was never installed. – Nathan Osman Oct 26 '11 at 18:17
  • 1
    @George Edison - There is also package holding, which allows you to not update the package. so Holding a package basically means you're telling the package manager to keep the current version no matter what. This is useful if more recent version of a currently working program breaks after an update. (you can't hold a package that was never installed also see my question is the same).... i tested that right now - see he said disable packages from the auto-update – hhlp Oct 26 '11 at 18:41
  • 1
    Since this question was asked before we moved from apt-get to apt, it's worth noting that apt-mark hold packagename is still the standard solution for this. Trying apt hold will just complain with E: Invalid operation hold – mwfearnley Jan 07 '22 at 10:41

15 Answers15

827

Holding

There are different ways of holding back packages: with dpkg, apt, dselect, aptitude or Synaptic.

dpkg

Put a package on hold:

echo "<package-name> hold" | sudo dpkg --set-selections

Remove the hold:

echo "<package-name> install" | sudo dpkg --set-selections

Display the status of all your packages:

dpkg --get-selections

Display the status of a single package:

dpkg --get-selections <package-name>

Show all packages on hold:

dpkg --get-selections | grep "\<hold$"

apt

Hold a package:

sudo apt-mark hold <package-name>

Remove the hold:

sudo apt-mark unhold <package-name>

Show all packages on hold:

sudo apt-mark showhold

dselect

With dselect, enter the [S]elect screen, find the package you wish to hold in its present state and press = or H. The changes will take effect immediately after exiting the [S]elect screen.


The following approaches are limited in that locking/holding a package within aptitude or synaptic doesn't affect apt-get/apt.

aptitude

Hold a package:

sudo aptitude hold <package-name>

Remove the hold:

sudo aptitude unhold <package-name>

Locking with Synaptic Package Manager

Go to Synaptic Package Manager (System > Administration > Synaptic Package Manager).

Click the search button and type the package name.

When you find the package, select it and go to the Package menu and select Lock Version.

Synaptic menu

That package will now not show in the update manager and will not be updated.

DJCrashdummy
  • 1,911
hhlp
  • 42,002
  • 6
    This also works to prevent a package from being installed. When installing devscripts, a lot packaged are pulled as Recommended packages. As I don't need a mailserver (postfix), I could disable the installation of it by running echo postfix hold | sudo dpkg --set-selections before running sudo apt-get install devscripts. This hold action persists only for this installation, after the installation the selections are reset. – Lekensteyn Aug 20 '11 at 10:47
  • 8
    Also worth pointing out, package holds do break upgrades and patches sometimes by creating a situation where there is no legal solution apt can calculate to a dependency. If package foo has a == < or <= dependency on libbar, then apt will refuse to upgrade libbar as well as foo. Over time, these cascading dependencies may grow to block a large number of updates, including important security updates. You'll need to either remove the hold and let the upgrade happen, or rebuild the packages you are holding against newer versions of its dependencies if this happens. – Stephanie Aug 02 '12 at 05:22
  • 2
    Just a note: apt-mark doesn't support hold in version 0.7.25 (Ubuntu Lucid) – Joril Apr 02 '13 at 07:30
  • How can this be achieve in muon (kubuntu's update manager)?. Thanks in advance. Also, the package was downloaded (older version of chromium) so it isn't appearing in the muon GUI (at least what I see), it is appearing on the update manager though. – Hans Feb 03 '15 at 04:16
  • 2
    I can confirm that sudo apt-mark hold/unhold currently works in Ubuntu 16.04 (Xenial Xerus). I held some obsolete packages and then executed sudo apt-get dist-upgrade in order to see if they would be upgraded, but the held packages were not upgraded. By the way, you can hold/unhold several packages at once. Example: sudo apt-mark hold thunar thunar-dbg thunar-data libthunarx-2-0 libthunarx-2-dev. Nice! – Yuri Sucupira Sep 03 '16 at 04:20
  • If I could bump you up by 2 points I would. Your advice for how to use Synaptic to tell apt not to upgrade packages X, Y, Z was incredibly helpful! I have not tested your other methods for blacklisting certain packages b/c the Synaptic version worked perfectly! Thanks! – Ev- Oct 21 '17 at 02:09
  • 2
    Could someone here define the difference between holding and locking? – nutty about natty Oct 23 '17 at 22:31
  • 1
    Also, a bit of elaboration as to what apt, aptitude, dpkg, etc are, what they do, how they differ and whether for preventing a given package from updating all/either/some of these commands need to be run would not go amiss. The current answer is too terse and presupposes too much background knowledge (imho). -- For a bit of relevant/important background reading and commentary, read, for instance, this: https://askubuntu.com/questions/18654/how-to-prevent-updating-of-a-specific-package#comment102573_86229 – nutty about natty Oct 24 '17 at 19:05
  • 1
    How about packages installed from snap market? – Amir Fo Aug 11 '19 at 07:12
  • Using apt-mark hold is preventing me from upgrading from Ubuntu 19.10 to 20.04:
    hin@xps:~$ update-manager -d
    Gtk-Message: 22:22:12.308: Failed to load module "appmenu-gtk-module"
    Checking for a new Ubuntu release
    Please install all available updates for your release before upgrading.
    

    However, I have run sudo apt update && sudo apt upgrade

    – kirk Apr 23 '20 at 20:23
  • 2
    just a note: at least nowadays the hold-flags from dpkg, apt-mark, apt and aptitude are honored by each other. and even Synaptic kind of recognizes them: the held packages are still shown as upgradeable (if there is something to upgrade to of course) and you can mark them manually to upgrade, but when hitting the button "Mark All Upgrades" they are left out. but locking via Synaptic seems to still be "Synaptic-exclusive". – DJCrashdummy Feb 20 '21 at 06:18
  • 1
    As even more packages are nowadays recommending all kind of crap, it's good to know about sudo apt install --no-install-recommends the-package-name. That way you don't need to apply any hold tricks to avoid installing unneeded packages. – Mikko Rantalainen Jul 14 '21 at 14:03
  • Is it worth promoting the apt-mark hold option to the top of this answer? As far as I can tell, that's the recommended method now. – mwfearnley Jan 07 '22 at 10:43
  • The synaptic method failed to hold for me. – nyxee Feb 24 '22 at 17:14
  • With sudo apt-mark hold, how can you apply it to all packages? – Nathan B Aug 22 '22 at 21:16
53

I was looking for the same thing and after a lot of research I found that using the following syntax you can forbid one specific version but allow the next update:

Package: compiz-plugins-main
Pin: version 1:0.9.7.0~bzr19-0ubuntu10.1
Pin-Priority: -1

This goes into the /etc/apt/preferences file.

pevik
  • 453
soger
  • 731
  • 6
  • 8
  • 16
    This is a much better way than preventing updates indefinitely – Eero Aaltonen Sep 30 '13 at 10:31
  • With this method, I think, chances are bigger to prevent ubuntu 'adware' like ubuntu one or the amazon icon from being reinstalled with the next release upgrade... – Daniel Alder Jan 10 '14 at 21:29
  • This method also prevents Aptitude from reporting that a package is "Upgradable" (assuming an older version is being used than is available in the repo's) – Digger Oct 08 '20 at 21:14
  • 2
    @Digger but once a newer version appears, I mean newer than the one pinned to -1, aptitude will once again report the package as upgradeable. – soger Oct 09 '20 at 20:05
  • After using this, you can check with apt list --upgradable. If you need to prevent multiple packages, see https://superuser.com/a/678411/316381 or just created multiple files in the folder /etc/apt/preferences.d/ – Phlogi Jan 09 '23 at 06:40
45

To put a package "foo" on hold:

echo "foo hold" | dpkg --set-selections

In your case we are going to put wine on hold:

sudo -i
echo "wine hold" | dpkg --set-selections

To remove the hold:

sudo -i
echo "wine install" | dpkg --set-selections
Panther
  • 102,067
  • 3
    Also note that while a package is on hold, you can install a specific version via apt-get install wine=1.2.3. Being on hold prevents apt-get (dist-)upgrade from changing it. – rcoup Jan 06 '15 at 02:24
  • @rcoup If you have an old version on hold, and then you manually upgrade to a new version without removing the hold as you describe, will the old version be kept in the cache so that you can go back to it? – cxrodgers Aug 24 '18 at 14:40
  • 3
    @cxrodgers the local cache (typically /var/cache/apt/archives) is independent of holds & upgrades & stuff, so all the versions you've downloaded will be there until you run apt-get [auto]clean – rcoup Aug 27 '18 at 12:31
23

Install synaptic using sudo apt-get install synaptic.

Run using gksudo synaptic and on the search box locate the package you want to lock, ie: gedit

enter image description here

From the package menu select Lock version:

enter image description here

And that is all, the version currently installed at the time of the lock will stay installed even during upgrades.

Bruno Pereira
  • 73,643
  • 11
    Please look at "Lock version is not as clever as it sounds. It's supposed to do what it says on the tin, lock the version... But it only locks it within Synaptic. Anything else that does package upgrades (read: Update Manager, apt-get, aptitude, etc) ignores this. This is probably buggy behaviour so I would expect this to be fixed in time." from http://askubuntu.com/questions/9607/what-does-lock-version-do. What is the current state? If something is locked in Synaptic, will other package managers "honor" the lock? –  Dec 22 '11 at 12:09
  • 2
    vasa1: As of version 0.75.13, still no :( Same problem with aptitude. – syockit Nov 17 '12 at 07:25
  • As of 0.84.3 (Jan '21) it still does not use apt-mark – Force Jan 08 '21 at 00:20
16

Preventing a package from being installed is called "package holding" and it is very simple to do:

echo package_name hold | dpkg --set-selections

...where *package_name* is the name of the package you want to prevent from installation.

Note: the above command assumes root privileges. In other words, you will probably need to type sudo su before running it.

Nathan Osman
  • 32,155
RobotHumans
  • 29,530
13

Since some time apt-get is replaced by apt, so for example I want to prevent Firefox from updating to version above 56, because a lot of add-ons, like "Tab Groups" don't work any more with the new Firefox 57 (see "WebExtensions Update").

It is possible to hold more than one packages with one command and use wildcards.

Prevent Firefox from updating

sudo apt-mark hold firefox firefox-locale-*

If you should deside to unhold them later, that would be the command:

sudo apt-mark unhold firefox firefox-locale-*
rubo77
  • 32,486
6

Everything you ever wanted to know about "holding" and "pinning" packages to specific versions: https://help.ubuntu.com/community/PinningHowto

4

Adding details to @soger's comments relative to Ubuntu 16.04.

Ubuntu 16.04 does not have an existing /etc/apt/preferences file by default. If you don't have one currently, just create a new file and populate it with a stanza as @soger describes above to exclude the given package and its dependencies from updates.

Afterwards, run apt update and you're GTG. :0)

For example, I have an Ubuntu 16.04.5 LTS server with embedded Intel video card and an NVidia card. The NVidia card is the only one used. The server also uses CUDA drivers. I had a problem where apt kept insisting

va-driver-all

(Intel drivers) required an update, but it could not determine which version to install. This was driving me nuts, and I didn't need the Intel drivers anyway. I entered this text into the preferences file and flushed apt, problem solved.

Package: va-driver-all
Pin: release *
Pin-Priority: -1
MrPotatoHead
  • 217
  • 2
  • 3
4

I synaptic you can freeze the version of a specific package I'm not a 100% sure as to whether this will amend apt-get but it will definately stop update manager.

To freeze a package select it in synaptic then open the package menu and select freeze version.

Hope this helps

edit: This question 16668 deals with a similar situation

Allan
  • 11,582
3

Just because it was not mentioned here, the KDE tool Muon has an option similar to Synaptic's:

enter image description here

enter image description here

cipricus
  • 3,444
  • 2
  • 34
  • 85
3

See bugs #75332, #158981 and #72806.

The summary is that hold at apt-get / aptitude level is not triggering hold status in dpkg (see bug 72806 especially) and update-manager reads status from dpkg.

workaround is run as root: echo "package hold" | dpkg --set-selections

notpeter
  • 1,569
jasper
  • 31
2

You can use on aptitude the "specific override", like this:

aptitude reinstall ~i oracle-java8-jre:

This is a one time only use of (not stored for future reinstalls), keep specific override, to reinstall all packages in your system but not oracle-java8-jre.

If you use a keep specific override, the package will momentarily be in a state of keep and aptitude will not try to install it.

A very good thing if you think your system was compromised some how as you can reinstall everything in just one punch card.

1

To keep a package at the currently-installed version and prevent it from being automatically upgraded, you can add an APT preference fragment to /etc/apt/preferences.d like this:

Package: vim
Pin: release a=now
Pin-Priority: 1001
Kenyon
  • 132
1

If you have Synaptic installed you can select the package and use the menu Package -> Lock Version to prevent it being updated.

You can install Synaptic with sudo apt-get install synaptic. I personally find it more useful than the Software Center... then again, I'm fairly old school. :)

dinchamion
  • 271
  • 1
  • 9
0

Occasionally one might want to hold back all the packages currently installed. Here's how.

First save the current state, so you can undo:

dpkg --get-selections > current_selections.txt

Then, to hold back all the packages:

dpkg --get-selections | sed -r "s/\tinstall/hold/" |dpkg --set-selections

Finally, when you want to revert back to the previous state:

dpkg --set-selections < current_selections.txt

One use case for this might be when creating a VM or Amazon AMI snapshot to migrate from a QA to production environment.