Many times when the installation of packages on the computer is generated, some errors also arise. That is why, in this article, you will learn how to resolve package dependencies in Ubuntu Linux?

What is a broken package in ubuntuv?

When the installation of a package begins, there are two possibilities: that the entire process is carried out correctly, or that, on the contrary, it is not compatible with the other programs on the computer.

The broken package is responsible for not being able to perform some activities, such as installing or uninstalling programs. In addition, it does not allow you to update any of the packages either.

A broken package in Ubuntuv can be generated for different reasons. And then we leave you some of the causes:

  • When you are installing programs external to the official distribution repositories.
  • If the installation is accidentally interrupted.
  • If the operating system update is interrupted.
  • Among others.

What are broken dependencies in Linux?

From the moment you want to install a package or a program in Linux, you should know that you do not need only that one, you are also going to use different files or programs classified as complementary, necessary for the operation of the main package.

However, when the packages are not found within the computer system this error is generated.

The solution in most cases for this problem is to install new packages on which the main one depends. 

So, a broken dependency in Linux is any package that is needed and that is not inside the distribution's repositories. When broken packages are generated, broken dependencies or errors also arise.

Step by step to resolve package dependencies on ubuntu, linux

In the event that you have some broken packages, you need to carry out some processes to solve them. It is recommended that you read very well before applying any of the solutions to avoid deleting good programs.

Fix broken packages with dpkg and the apt package manager

  • The first step is to configure the packages that were unpacked, but could not complete their installation. To achieve this, you need to start running the command sudo dpkg—configure -a.
  • Now, if the problem still can't be fixed, you should try deleting the local cache of the packages, using some commands, like: sudo apt-get clean y sudo apt-get autoclean.
  • Now, the next thing is to restore the deleted cache from the repositories to detect and repair the problems that are occurring in the system dependencies. For this you must write the command: sudo apt-get update –fix-missing.
  • You should then use apt to try to fix all broken dependencies and broken packages that exist. You must place: sudo apt-get install -f.
  • Now, if you still have problems, the next thing to do is delete the apt and dpkg lock files. For this you must write: sudo rm /var/lib/apt/lists/lock, sudo rm /var/cache/apt/archives/lock, y sudo rm /var/lib/dpkg/lock.

Once you finish applying all the steps, you need to repeat the first and second steps to complete the entire process. 

Fix broken packages and dependencies with terminal and dpkg

  • If you have carried out all the steps above, and the problem still persists, the solution is to remove the broken package that most likely causes the errors. Write the command sudo apt-getremove.
  • If the first step doesn't work, you should now find the package that is causing the problem, by issuing the command: sudo dpkg -l | grep ^..r
  • The next thing is to force the uninstallation of the package that is presenting the problems. You must write: sudo dpkg --remove --force-remove --reinstreq package-name. Note that this last part must be replaced by the broken package.
  • Continue clearing the local cache of the repository. Put the command of: sudo apt-get clean, y sudo apt-get autoclean.
  • Afterwards, you must update the operating system, placing the command in the terminal: sudo apt-get update, y sudo apt-get dist-upgrade.

If the entire system updates without any issues, then the steps worked perfectly.

Fix broken packages with Synaptic package manager

It is a really simple alternative, you just have to install the program on your computer, and you do this by typing the command in the terminal: sudo apt-get install synaptic.

  • The next thing you should do is open the program, and click on the option ''Filters''. 
  • Then you must select the option ''Broken''. 
  • Now, you can select the name of the package that is generating the error.
  • Continue right-clicking your mouse until the menu appears, and look for the option ''Mark to uninstall completely''. 
  • If the problem continues, the moment you open the Synaptic package manager go to the menu ''Edit'', and look for the option to repair broken packages. In this way, Synaptic will immediately try to repair all the programs of the operating system.

Other alternatives to fix package dependencies

In the event that the alternatives mentioned above do not work, there are also others that you can apply on your computer.

Edit the file /var/lib/dpkg/status

To achieve this, you need to run the command sudo nano /var/lib/dpkg/status. This is an important process because it contains all the information about the status of the operating system packages.

Once you open the text editor, you should look for the information block that refers to the package that is generating the error, and when you find it, it should be removed.

Other frequently asked questions

How do I clean broken packages in Ubuntu?

When you already have the specific package in which the package is having problems, this is one of the options you have to clean up your computer, so that the hard drive has more space as well. 

  • The first thing you should do is clean up and delete all the cache files of the package that is corrupted. For this you must place the command: sudo rm -rf /var/cache/apt/archives/nodejs-0.10.28-1chll~trustyl_amd64.deb
  • Afterwards, you should run the automatic cleanup command, and update the repository by placing sudo apt-get autoclean, sudo apt-get update, y sudo apt-get upgrade.
  • Another option is to use the command ''move'', and thus, change the place where all the cache files are saved.

How do I fix sudo apt-get update?

Sometimes sudo apt-get update generates some errors that need to be fixed. And, it is a very simple process:

  • You must open the terminal, and place the command: sudo rm /etc/apt/sources.list, and press enter to place sudo rm/etc/apt/sources.list.d/* -vf.
  • Then you click on intro, and you write: sudo software-properties-gtk.
  • A new window opens, and you must select the options you want to update.
  • To finish you must close the window, and write in the terminal: sudo apt-get-update.

How do I repair my Ubuntu repository?

The best thing to do is to reset the Ubuntu repositories, and you must do it by following some very simple steps:

  • The first thing you should do is open a terminal.
  • Next, you should make a backup copy of the file where the repositories are stored. And, you must move sources.list to the personal folder, placing sudo mv /etc/apt/sources.list ~ /.
  • The next thing you should do is a reset by placing another command: sudo touch /etc/apt/sources.list.
  • Depending on the operating system you have, the next step will be to directly open the ''Software and updates''. In the case of systems with a Plasma graphical environment, you must open Discover, select Fonts, and then in ''Software sources''.
  • When you enter the next thing you should do is check the first tab, and the third. 
  • Then in the option ''Updates'', you must activate all that interest you.

Continue pressing the option ''To close''.