Software & AppsOperating SystemLinux

How To Find and Reinstall Corrupted Packages in Ubuntu

Ubuntu 18

In this article, we will walk you through the process of finding and reinstalling corrupted packages in Ubuntu. This is a crucial task for system administrators and users alike, as corrupted packages can cause various issues, including system instability and software malfunctions.

Quick Answer

To find and reinstall corrupted packages in Ubuntu, you can use the debsums tool to check for missing or modified files. Once identified, you can reinstall the packages using the apt-get command with the --reinstall option. Regularly checking and fixing corrupted packages is crucial for maintaining a stable and functioning Ubuntu system.

Understanding the Need for Package Reinstallation

Packages in Ubuntu can become corrupted due to various reasons, such as abrupt power failures, disk write errors, or even malware attacks. When a package is corrupted, it may not function as expected, leading to system errors. Therefore, it’s essential to identify and reinstall these corrupted packages to ensure the smooth operation of your Ubuntu system.

Tools Required

To accomplish this task, we will be using a tool called debsums. debsums computes MD5 hashes of files in your system and compares them against the MD5 hashes stored in the package’s control file. If there are any discrepancies, it indicates that the files have been modified or are missing, signifying a corrupted package.

Installing debsums

If debsums is not already installed on your system, you can install it using the following command:

sudo apt-get install debsums

This command uses sudo to execute the command with root privileges, apt-get is the package handling utility in Ubuntu, and install is the command to install a new package.

Checking for Corrupted Files

Once debsums is installed, you can use it to check for corrupted files. Run the following command:

sudo debsums -cs

Here, -cs stands for ‘check’ and ‘silent’. This command will only display the names of packages with missing or modified files.

If you also want to include configuration files in the check, you can use the -a option:

sudo debsums -as

The -as option stands for ‘all’ and ‘silent’. This command will display the names of all packages with missing or modified files, including configuration files.

Reinstalling Corrupted Packages

After identifying the corrupted packages, the next step is to reinstall them. Use the following command:

sudo apt-get install --reinstall $(dpkg -S $(debsums -c) | cut -d : -f 1 | sort -u)

This command might seem complex, so let’s break it down:

  • dpkg -S $(debsums -c) fetches the names of the packages with corrupted files.
  • cut -d : -f 1 extracts the package names from the output.
  • sort -u removes duplicate package names.
  • sudo apt-get install --reinstall reinstalls the identified packages.

Reinstalling Packages with Missing Files

If you have missing files rather than corrupted files, you can use a similar command to reinstall the packages:

sudo apt-get install --reinstall $(dpkg -S $(debsums -c 2>&1 | cut -d " " -f 4 | sort -u) | cut -d : -f 1 | sort -u)

This command works similarly to the previous one, but it specifically targets missing files.


In this article, we’ve covered how to find and reinstall corrupted packages in Ubuntu using debsums and apt-get. It’s important to remember to exercise caution when working with system files and packages. Always ensure to back up your important data before making any changes to your system.

Remember, a well-maintained system is the key to a smooth and hassle-free computing experience. Regularly checking for and fixing corrupted packages can help keep your Ubuntu system in top shape.

What are the common signs of a corrupted package in Ubuntu?

Common signs of a corrupted package in Ubuntu include system errors, software malfunctions, unexpected crashes, and missing or modified files.

Can I reinstall all packages on my Ubuntu system?

While it is possible to reinstall all packages on your Ubuntu system, it is not recommended unless absolutely necessary. It is better to identify and reinstall only the corrupted packages to avoid any unintended consequences.

How can I prevent packages from getting corrupted in Ubuntu?

To prevent packages from getting corrupted in Ubuntu, it is important to ensure that your system is running on stable power, regularly update your packages and system, and be cautious while installing third-party software or making system modifications.

Are there any risks involved in reinstalling corrupted packages?

Reinstalling corrupted packages generally carries minimal risk. However, it is always recommended to have a backup of important data before making any changes to your system, including package reinstallation.

Can I use a different tool instead of `debsums` to check for corrupted packages?

Yes, there are alternative tools available to check for corrupted packages in Ubuntu, such as rpm -V for RPM-based distributions. However, debsums is the recommended tool for Ubuntu as it is specifically designed for Debian-based systems.

Leave a Comment

Your email address will not be published. Required fields are marked *