How to find and repair broken packages on Linux

You can use package managers in Linux to control the installation and removal of packages. In addition to this, package managers also help you find broken packages on your system and reinstall them to fix various problems related to Linux packages.

If you don’t know what commands to use to find and repair broken packages in Linux then this guide is for you. We’ll briefly cover broken packages, how to check if your system has broken packages, and how to properly install them.

What are broken packages?

When you install a new package on Linux, your system’s package manager is responsible for the entire installation process. These package managers have built-in methods for handling exceptions and errors. But sometimes, in the event of unexpected problems, the installation will stop and the entire package will not be installed. Such packages are called defective packages in Linux.

Package managers like APT do not allow any further installation of packages if it finds a defective package on the system. In such a situation, repairing the defective package is the only option.

How to find and repair broken packages

Each package manager processes different types of packages. To the example, DNF, and YUM work with the Red Hat Package Manager (RPM) to download and install RPM packages. Similarly, APT acts as a front-end wrapper for the base software dpkg on Debian-based distributions.

Reinstall defective packages under Debian

APT is the standard package manager that comes pre-installed on every Debian-based distribution. Aside from APT, Debian and Ubuntu users can also download and install packages manually using dpkg.

How to repair broken packages on Debian-based distributions with APT:

  1. Open the terminal by pressing Ctrl + Old + T on your keyboard and enter:

    sudo apt --fix-missing update
  2. Update your system’s package list from the available sources:

    sudo apt update
  3. Now force the installation of the defective packages with the -F Flag. APT will automatically search for defective packages on your system and reinstall them from the official repository.

    sudo apt install -f

If the above steps don’t work for you, then you can try using dpkg to resolve the issue.

  1. Force dpkg to reconfigure any pending packages that are already unpacked but need to be configured. the -a Flag in the command stands for All.

    sudo dpkg --configure -a
  2. Send grep with dpkg to get a list of all packages saved as. are marked Necessary by dpkg.

    sudo dpkg -l | grep ^..r
  3. Use the –Extinguish Flag to delete all defective packages.

    sudo dpkg --remove --force-remove-reinstreq
  4. Clean up the package cache and install scripts with it appropriately clean.

    sudo apt clean
  5. Now update your system’s package lists with the following command:

    sudo apt update

Repair broken packages on Fedora/ CentOS and RHEL

While YUM and DNF are great when it comes to automatically managing broken packages, problems sometimes arise because there are thousands of packages installed on a Linux system. In such situations, you can use RPM (the base package manager for Fedora and CentOS) to quickly fix such problems.

  1. Check all packages on your system with the -V Flag.

    sudo rpm -Va
  2. You will see a long list of all the packages installed on your system.

  3. Reinstall the package that you believe is causing the problem with the damaged package.

    sudo dnf --refresh reinstall packagename

The above steps are very cumbersome – it is a hassle to determine which package is causing the problem from a list of hundreds. While RPM is a powerful package manager and you will rarely encounter such problems, it is still important to know how to fix these problems should you run into a similar situation in the near future.

Manage packages on Linux distributions

Package managers on Linux are able to handle most problems, including failed installations. But sometimes various problems arise that can only be solved intuitively. The solution to repairing broken packages involves several steps – identifying the broken package, reinstalling it, and updating the system’s package list.

There are tons of Linux distributions out there on the internet worth trying out, but basically each of them has a similar foundation. Desktop environments give each distribution a unique user experience. Choosing an ideal desktop environment that suits your tastes should be your priority once you’ve finally made your decision to adopt Linux.

Related Posts