How To Exclude Packages from Apt-Get Upgrade

Exclude Packages from Apt-Get Upgrade

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 the 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 from Upgrade

Use the following command to exclude or hold a specific Debian package from an update. This will turn off the updates of specified packages from an automatic upgrade or manual upgrades. Using apt

$  sudo apt-mark hold package_name

  • Exclude Packages from Apt Upgrade

  • Using dpkg

  • $  echo "package_name hold" | sudo dpkg --set-selections

  • Using aptitude

  • $  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 Enable Package Upgrade

In the 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. Using apt

$  sudo apt-mark unhold package_name
  • Using dpkg
  • $  echo "package_name install" | sudo dpkg --set-selections
  • Using aptitude

  • $  sudo aptitude unhold package_name 

Now, the unhold packages will be upgraded with apt upgrades or unattended-upgrades.

Conclusion

In this tutorial, you have learned to hold packages from unnecessary upgrades. You can remove hold at any time from the package to allow an upgrade again.

2 comments

  1. Thanks bro, it's god damn so fucking good, Really helpful.. Cheers
    1. Thanks ya
© LinuxFault. All rights reserved. Developed by Jago Desain