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?”
Also Read: Deprecated Linux Commands you Should Avoid to Use Right Now and Use Their Replacements
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.
Table of Contents
[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.
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.
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.
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.
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.
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.
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.
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 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.
[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.
Next, follow the below steps in series.
- Launch the Synaptic Package Manager from the application launcher
- Search for your desired package
- Select your target package (it will be highlighted)
- Then go to the package menu and click on the version lock option
Below is the representation of the above steps.
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.
Innovative tech mind with 12 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.