How to Prevent a Specific Package from Updating in Ubuntu (apt-mark hold)

Keeping your Ubuntu Linux system updated is essential for security and stability. However, there are times when you might need to prevent a specific software package from automatically updating when you run sudo apt upgrade. This is common when you are relying on a legacy application, a specific library version, or a custom kernel that breaks with newer releases.

You can “hold” a package at its current version using the apt-mark command, ensuring it is ignored during system-wide upgrades.

How to Hold a Package Using apt-mark

The apt-mark command allows you to change the state of a package in the Debian/Ubuntu package manager. To prevent a package from being upgraded, you use the hold argument.

  1. Open your terminal application.
  2. Run the following command, replacing package_name with the exact name of the software you want to lock:

sudo apt-mark hold package_name

For example, if you want to stop the Nginx web server from updating, you would run:
sudo apt-mark hold nginx

The system will output a confirmation message: package_name set on hold.

How to Verify Held Packages

If you forget which packages you have locked, you can easily view a list of all currently held packages by running:

apt-mark showhold

This will output a simple list of every package that is currently blocked from automatic upgrades.

How to Unhold a Package

When you are ready to allow the package to update again (for example, if a bug in the newer version has finally been patched), you can remove the restriction using the unhold argument:

sudo apt-mark unhold package_name

The system will output: Canceled hold on package_name. The next time you run sudo apt upgrade, the package will update normally along with the rest of your system.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.