Sometimes we upgrade packages accidentally which is not to update. It also happens during the full update or automatic packages upgrade process. This creates serious issues on the server. For example, You need to exclude kernel, PHP, MySQL and Apache packages from getting updated while updating system via apt update. This tutorial will help you find the answer of how to exclude packages from Apt-get update? How to use exclude package in Ubuntu? How to prevent packages from auto update using apt?
Hold or Exclude Packages
Use the following command to exclude or hold specific Debian package from an update. This will turn off the updates of specified packages from an automatic upgrade or manual upgrades.
sudo apt-mark hold package_name
echo "package_name hold" | sudo dpkg --set-selections
sudo aptitude hold package_name
Change the package_name with your actual package name to be set on hold.
List Packages on Hold
You can check the packages on hold anytime. Use the following command to view all packages already set to hold.
sudo dpkg --get-selections | grep "hold"
Unhold or Include Package in Install
In future, If you need to upgrade any package set on hold. You need to unhold any package before an upgrade. Use one of the following commands to unhold any package.
sudo apt-mark unhold package_name
echo "package_name install" | sudo dpkg --set-selections
sudo aptitude unhold package_name