How to Exclude Package Update from Apt-Upgrade

Whenever you hit the apt upgrade command on your Ubuntu or other Debian-based distribution, it will update the existing package and application to the latest release.

You might not have a problem updating the packages to their latest release. But let me remind you, “How many times did you break your packages after updating the system?”

The answer might be occasionally, and you don’t even have any problem with that. However, the term becomes intense for server admins running multiple nodes on the server.

For example, if the server is running a web application, it might be using technologies like PHP, Python, MySQL, NGINX, Apache, etc. If those packages are broken due to an update, then you or your organisation might face downtime.

And downtime is no fun topic to take lightly; even 1-second of downtime can affect your user experience on a big scale. So, in such a situation, usually, the update is tested in the development environment and the auto-update for the production environment is paused and manually rolled out when it has been tested and worked perfectly.

Today, you will learn how to pause, unpause, and list the paused packages on Ubuntu, Linux Mint, Pop!_OS, and other Debian-based distributions using the CLI and GUI methods.

[CLI] How to Hold or Exclude Packages from Upgrade

The default APT package manager provides you with many useful features. One of them is holding packages from getting updated. However, there are other ways to do the same things by using DPKG and aptitude commands.

For example, if you want to pause an auto-update for the NGINX package, you can use either APT-MARK, DPKG, or Aptitude commands, as shown below.

Using APT command

Execute the below command to turn off automatic updates for the NGINX package (replace the NGINX package name you’re trying to target) with a system update from the command line.

$ sudo apt-mark hold nginx

Below is the output of the above command.

Hold package update using APT-MARK command
Hold package update using the APT-MARK command

You can hold multiple packages by specifying space between each package name as separation.

Using DPKG command

Execute the below command to exclude the auto-update for the NGINX package with a system update using the DPKG command.

$ echo "nginx hold" | sudo dpkg --set-selections

Below is the output of the above command.

Hold package update using DPKG command
Hold package update using DPKG command

Using the Aptitude command

If you are using an interactive APT frontend package manager like the aptitude command, then you can execute the below command to hold the auto-update for the NGINX package with a system update.

$ sudo aptitude hold nginx

Below is the output of the above command.

Hold package update using Aptitude command
Hold package update using the Aptitude command

How to List Packages on Hold

After holding/pausing/disabling packages from the update, you can view the list of packages on hold by using any of the following commands.

Using an APT command

Using the same apt-mark command used for holding the package can be used to view the list of packages on hold.

$ apt-mark showhold

The following packages have been kept back from updating.

Check the packages on hold using APT-MARK command
Check the packages on hold using the APT-MARK command

Using DPKG command

You can pipe the grep command with the dpkg command to view the list of packages on hold, as shown below.

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

Below is the output of the above command.

Check the packages on hold using DPKG command
Check the packages on hold using “dpkg” command

How to Unhold or Enable Package Upgrade

In future, if you want to unhold packages, set them to hold using any of the above-mentioned methods. Then use one of the following commands to unhold any package.

Using APT command

Specify the package name with unhold syntax, as shown below.

$ sudo apt-mark unhold nginx

Below is the output of the above command.

Unhold package update using APT-MARK command
Unhold package updates using the APT-MARK command

Using the DPKG command

Execute the below command with your target package to unhold it from the dpkg command.

$ echo "nginx install" | sudo dpkg --set-selections 

Below is the output of the above command.

Unhold package update using DPKG command
Unhold package updates using the DPKG command

Using the Aptitude command

Aptitude provides you unhold option to enable packages disabled from the upgrade.

$ sudo aptitude unhold nginx

Below is the output of the above command.

Unhold package update using Aptitude command
Unhold package update using Aptitude command

Unhold All Packages

If you have paused multiple packages from getting updated with a system upgrade, then execute the following command to unhold all packages using the apt command.

$ sudo apt-mark unhold $(apt-mark showhold)

Below is the output of the above command.

Unholding All Packages using the APT-MARK command
Unhold All Packages using the APT-MARK command

[GUI] Prevent Package Updates using Synaptic Package Manager

There was a time when the Synaptic package manager was the default GUI package manager for Ubuntu, but now it’s replaced with the GNOME package manager.

However, the rich functionality of synaptic to hold packages from updates can be still used by installing synaptic on your system using the following command.

$ sudo apt install synaptic

Below is the output of the above command.

Installing synaptic on your system
Installing Synaptic on your system

Next, follow the below steps in series.

  1. Launch the Synaptic Package Manager from the application launcher
  2. Search for your desired package
  3. Select your target package (it will be highlighted)
  4. Then go to the package menu and click on the version lock option

Below is the representation of the above steps.

Prevent Packages Update using Synaptic Package Manager
Prevent Packages Update using Synaptic Package Manager

Wrap Up

That’s all you have to know about holding, unholding, and listing the packages on hold. If you have any questions regarding this topic, then feel free to contact us in the below comment section.

Leave a Reply