Debian

Use apt-get to fix missing and broken packages

Package managers in Linux are the most useful programs that are used to add additional capabilities in a system. They can be used for installing, removing, updating, and upgrading the packages, also featuring the dependency resolution capabilities. However, like any other program, things can also go wrong with these package managers. Sometimes, while updating or installing a third-party program, installation goes wrong and results in errors that require you to install the missing dependencies and broken packages. This error may also occur because of improper package management, incorrect installation of packages, and installation of unnecessary packages. Whatever the reason may be, the problem is that you receive an error and left with a condition where you cannot add a new package nor update or delete the existing packages until you fix the problem.

In this article, we will learn how to fix the missing dependencies and broken packages using the apt-get command. Note that, we have run the commands and procedure mentioned in this article on a Debian 10 system. The same procedure can be followed in Ubuntu and older Debian versions.

We will use the command-line Terminal for trying the solutions and fixing the problem. To open the Terminal application in Debian, hit the super key on the keyboard and search for it using the search bar that appears. When the search result appears, click on the Terminal icon to open it.

Using apt-get to fix missing and broken packages

Apt-get is a Terminal based package management tool used for installing, upgrading, and removing packages. Along with these features, it also has flags that can be used for fixing missing dependencies and broken packages.

Method 1

Use the “fix-missing” option with “apt-get update” to run the updates and ensure the packages are up to date and there is no new version available for the packages.

$ sudo apt-get update --fix-missing

Once you are done with the update, execute the below command in order to force the package manager to find any missing dependencies or broken packages and install them.

$ sudo apt-get install -f

Another approach to solving the broken package issue via apt-get is to edit the “/etc/apt/sources/list” file and adding sites with newer versions of packages available. Then running the “apt-get update” command to update the repository list.

If the above method does not fix the issue of broken dependencies and broken packages and still you are receiving the error, then try the following methods.

Other methods

Method 1:

In this method, we will use the “apt-get autoremove” and the “dpkg” in order to fix missing dependencies and broken packages.

1. Update the repository index by executing the below command in Terminal:

$ sudo apt-get update

2. Next, execute the below command to clean out the local repository:

$ sudo apt-get clean

3. Execute the below command to remove all the unnecessary packages that are no longer needed:

$ sudo apt-get autoremove

The above command will display the unmet dependencies or broken package’s name.

4. Then try executing the below command in Terminal to force remove the broken package:

$ sudo dpkg --remove -force --force-remove-reinstreq Package_Name

Method 2:

In the following method, we will use the “dpkg—configure” command in order to fix missing dependencies and broken packages.

Dpkg is a package management tool that can be used to install, remove and manage packages. Similar to apt-get, it can also help to fix broken packages and missing dependencies. If you receive some errors while installing or updating the packages, try the following solution with dpkg:

1. Execute the below command in the Terminal to reconfigure all the partially installed packages.

$ sudo dpkg --configure -a

If the above command does not work, like in our case and you see similar results displaying the erroneous package, then try removing the package.

2. Execute the below command in Terminal in order to remove the erroneous package.

$ apt-get remove <package_name>

3. Then use the below command to clean out the local repository:

$ sudo apt-get clean

After trying any one of the above solutions, run the update command to ensure the dependencies are resolved and broken packages are fixed or removed.

$ sudo apt-get update

Fixing the dependency and broken packages errors and then returning the system to the normal state may take hours. Sometimes it gets so complicated that when you finally fix it, you feel so lucky. We have presented some solutions regarding this error, so please give them a try. If you know some of the possible solutions we did not mention, please let us know in the comments.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.