Using the apt Command to Exclude Packages From Updates

Using the apt Command to Exclude Packages From Updates

This guide explains how to use the apt command to exclude or hold specific packages from updates in Ubuntu and Debian systems. This feature helps prevent automatic or manual upgrades of certain packages.

1. Holding a Package

To prevent a package from being updated, use the following command:

sudo apt-mark hold <package_name>

Replace <package_name> with the name of the package you want to hold. For example:

sudo apt-mark hold firefox

This command ensures the package remains at its current version, unaffected by upgrades.

 

2. Checking Packages on Hold

To view all packages currently on hold, run:

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

This command displays a list of packages marked as "hold."

 

3. Unholding a Package

If you need to upgrade a held package, unhold it first using the following command:

sudo apt-mark unhold <package_name>

For example:

sudo apt-mark unhold firefox

After unholding, the package can be updated through regular upgrade commands.

 

4. Notes and Best Practices

  • Use the hold feature cautiously to ensure critical updates are not missed, especially for security-related packages.
  • Always verify the package status using dpkg --get-selections after holding or unholding.
  • Consider documenting held packages for easy reference during system audits.
Was this article helpful?
0 out of 0 found this helpful