Posted on
Administration

Using apt-mark to manage package state

Author
  • User
    Linux Bash
    Posts by this author
    Posts by this author

Managing Package States in Linux: Mastering apt-mark and Beyond

When you start diving deeper into managing your Linux systems, especially those based on Debian, Ubuntu, Fedora, or openSUSE, understanding how to control package states becomes crucial. This knowledge not only helps in maintaining the stability of your systems but also provides you with the precision control needed to manage the packages effectively. In this blog post, we're going to explore how to use apt-mark with apt package manager and will also touch upon equivalent commands in dnf (used in Fedora) and zypper (used in openSUSE), illustrating how similar actions can be performed across these differing package managers.

Introduction to apt-mark

apt-mark is a command-line utility that allows you to mark packages as automatically or manually installed which helps in managing package dependencies during installation and removal. This tool is part of the apt package management system commonly found in Debian-based distributions like Ubuntu.

Using apt-mark

  1. Marking a Package as Manually Installed: To prevent a package from being automatically removed when its no longer needed, mark it as manually installed:

    sudo apt-mark manual [package-name]
    
  2. Marking a Package as Automatically Installed: If you want a package to be eligible for automatic removal when no longer needed, use:

    sudo apt-mark auto [package-name]
    
  3. Checking the Mark State of a Package: To see whether a package is marked as automatic or manual, run:

    apt-mark showmanual | grep [package-name]
    apt-mark showauto | grep [package-name]
    
  4. Holding a Package: To hold a package back from being upgraded:

    sudo apt-mark hold [package-name]
    
  5. Unholding a Package: To allow a package to be upgraded again:

    sudo apt-mark unhold [package-name]
    

Managing Package States in Fedora (dnf)

In Fedora, the dnf package manager handles package operations. While dnf doesn't directly have an equivalent to apt-mark, you can still achieve similar outcomes with different commands.

  1. Setting the Install State:

    sudo dnf mark install [package-name]
    
  2. Setting the Remove State:

    sudo dnf mark remove [package-name]
    
  3. Holding a Package: DNF provides a way to hold back packages from being updated using a version lock plugin:

    sudo dnf install dnf-plugins-core
    sudo dnf versionlock add [package-name]
    
  4. Removing the Hold:

    sudo dnf versionlock delete [package-name]
    

Managing Packages in openSUSE (Zypper)

For those using openSUSE, zypper is the package manager of choice. Similar to apt, it also offers capabilities to manage the package installation and removal criteria.

  1. Locking a Package: To prevent a package from being updated:

    sudo zypper addlock [package-name]
    
  2. Unlocking a Package: To allow a package to be updated again:

    sudo zypper removelock [package-name]
    

Conclusion

Understanding and using these package management tools effectively can significantly enhance your ability to maintain and control your Linux environment. Whether you’re using apt-mark in Debian-based systems, handling package states with dnf in Fedora, or managing locks with zypper in openSUSE, each tool offers robust functionalities for comprehensive package management. As you grow comfortable with these commands, you’ll find managing your system’s software more intuitive and less prone to unwanted changes.