
Comprehensive Guide to Using 'apt-mark' (with examples)
The apt-mark
command is a versatile utility within Debian-based systems that allows users to change the status of installed packages. This utility is essential for system administrators and power users who need to manage package installations with precision. By marking packages as either automatically or manually installed, holding their updates, or releasing them for updates, users can control their system’s package management more effectively. This command can also be used to display packages based on their installation status.
Mark a Package as Automatically Installed
Code:
sudo apt-mark auto package
Motivation:
Marking a package as automatically installed is useful when dependencies are involved. When you install a package that requires other packages, those additional packages are marked as automatically installed. If you later remove the initial package, the dependencies will automatically be removed too. This helps in keeping the system clean and free of unnecessary packages.
Explanation:
sudo
: This command is run with administrative privileges to allow changes to the package management database.apt-mark
: The main utility command to manage package installation statuses.auto
: This argument marks a package as automatically installed.package
: This represents the name of the package you wish to mark. It should be replaced with the actual package name.
Example Output:
Upon marking a package with this command, there is generally no output unless the package is not found, in which case an error message will be displayed, such as “E: Unable to locate package”.
Hold a Package at its Current Version and Prevent Updates to It
Code:
sudo apt-mark hold package
Motivation:
Holding a package is a crucial operation when you need a specific version of a package due to compatibility requirements or to avoid potential bugs in newer versions. This is particularly significant when managing servers or systems with specific software dependencies.
Explanation:
sudo
: Required to execute administrative tasks on the system.apt-mark
: Specifies the command used to change the package state.hold
: Sets the package in a held state preventing it from being updated when the system updates.package
: Substitute this with the package name you intend to hold.
Example Output:
Running this command will confirm the package is in a held state silently unless there is an issue, such as stating: “Note, selecting ‘package’ instead of ’exact-package-name’”.
Allow a Package to Be Updated Again
Code:
sudo apt-mark unhold package
Motivation:
There may come a time when the issues necessitating a package hold are resolved. You want to reintegrate it into the system’s update cycle. Using unhold
ensures the package receives updates, maintaining system security and functionality.
Explanation:
sudo
: Provides the necessary permissions to change the system.apt-mark
: Indicates the command performing the operation.unhold
: Removes the hold from the package, allowing it to be updated.package
: Replace with the appropriate package name you wish to release from hold.
Example Output:
This command will usually not produce output unless it confirms the action with: “package set on hold”.
Show Manually Installed Packages
Code:
apt-mark showmanual
Motivation:
Identifying manually installed packages can assist in managing system resource usage and redundancy. This list can guide you in trimming down superfluous software, thus improving system performance.
Explanation:
apt-mark
: Initiates the command used for package management.showmanual
: Displays a list of packages marked as installed manually by the user.
Example Output:
The command will output a list of packages manually installed:
package1
package2
...
Show Held Packages That Aren’t Being Updated
Code:
apt-mark showhold
Motivation:
It’s essential to keep track of held packages, especially when transitioning a system or when preparing for extensive updates. By listing these packages, administrators can reevaluate their need or determine if updates can now proceed.
Explanation:
apt-mark
: The foundation command used for package status queries.showhold
: Lists all packages currently in a hold state.
Example Output:
The output provides a clear list of held packages:
package3
package4
...
Conclusion
The apt-mark
command is invaluable for controlling the behavior and updating process of packages on Debian-based systems. Understanding and using this command effectively can greatly assist in maintaining an optimized and functioning system environment. Whether ensuring critical versions of software remain untampered or keeping a clean and efficient system, apt-mark
offers several indispensable options.