Did you know that package managers are the most useful programs to add additional capabilities to a Linux system? These programs can be used for installing, removing, updating, and upgrading your system packages. Additionally, they also feature dependency resolution capabilities.
Nonetheless, like any other program, things can not go as expected, so is the case with these package managers. This mostly happens during the update process or while installing a third-party program. The installation goes wrong, thus resulting in errors that require you to install the missing dependencies to fix the broken packages.
This error may also occur due to improper package management, incorrect installation packages, and installation of unnecessary packages. Whatever the motive maybe, at the end of the day, you receive an error, and you are left in a condition where you cannot add a new package, update or obsolete the existing packages until the problem is fixed.
This article will go through how you can fix the missing dependencies and broken packages using the apt-get command. Note that these commands can be run on any Debian-based computer version, including Ubuntu. However, in our case, we will run them on our Elementary OS.
We will also use the command line for trying various solutions to fix the problem.
Using apt-get to fix missing and broken packages
Generally, an Advance Package Tool(APT) is a free software user interface that works with core libraries to handle the installation and removal of software on Debian and Debian-based Linux Distros. The software simplifies the process of managing software on Unix-like computer systems by systematizing the retrieval, configuration, and installation of packages either from the precompiled files or by compiling source code. Along with these great features, it also has flags that can fix dependencies and broken packages.
Without further ado, let us get the article going by looking at the first method
Method 1
This structural method will use the “fix-missing” and “apt-get update” options to run the updates and ensure the packages are up to date. We will additionally use the same options to cross-check that there is no available update for packages.
sudo apt-get update --fix-missing
Immediately you are through with the update process, run the following command to force the package manager to look for any missing dependencies or broken packages and install them.
sudo apt-get install –f
Alternatively, you can use the second approach to solve the broken package issue found in the apt-get by editing the “/etc/apt/sources/list” file and adding sites with newer versions of available packages. After that, run the “apt-get update” command to update the newly added repo to the existing repo list of the system.
If the error persists even after running those two methods, go ahead and try the following methods.
Alternative methods
Method 1:
In this method, we will use the “apt-get autoremove” and the “dpkg,” a tool used to install, build, remove and manage Debian packages to fix the missing dependencies of all the broken packages.
Step 1: The first step is updating the repo index. To do this, run the following command in your terminal:
sudo apt-get update
Step 2: Next, you will execute the following command to aid in cleaning out the local repository:
sudo apt-get clean
Step 3: After that, you will copy and paste the following command into your terminal to remove all the unnecessary packages that are no longer needed:
sudo apt-get autoremove
once you run the above command, you may see the unmet dependencies or broken packages names.
Step 4: Once you see several broken packages, try executing the subsequent command in your terminal. This command helps to force the removal of broken packages:
sudo dpkg --remove -force --force-remove-reinstreq Package_Name
Note: Ensure you replace the “Package_Name” with the package you want to remove.
Method 2:
This method will use the “dpkg-configure” command to fix missing dependencies and broken packages.
Since dpkg is a package management tool that can install, remove and manage packages, so is apt-get. This is because the apt-get can also help fix broken packages and missing dependencies. In case you receive errors while installing or updating the packages, then try the following solution with dpkg:
Step 1: The first step in the method is to run the following command to aid reconfigure all the partially installed packages:
sudo dpkg --configure –a
If the above command does not work and you still receive similar erroneous messages, try removing the package. To remove a package, execute the following command:
apt-get remove <package_name>
Step 2: After removing the package, then use the following command that we previously used to clean out the local repository:
sudo apt-get clean
After that, run the update command to ensure that the dependencies are solved and the broken packages are either fixed or removed.
sudo apt-get update
Conclusion
Fixing the dependencies and broken packages errors and returning your system to a normal state may take several hours. At times it gets so complex that you feel super lucky after fixing it. However, this article has presented you with some solutions regarding this error, so we suggest giving them a try. If you have some of the tried and tested solutions that we did not mention, please reach us through the comment section. Otherwise, thanks for reading!