How to fix broken packages in Ubuntu

Apt, Ubuntu's package manager, is one of the most powerful and intuitive tools, but that doesn't mean that this manager never happens to be a problem. Sometimes, installing packages fails on Ubuntu and forcing users to figure out how to fix them. The great thing is that Ubuntu's package utilities, including Apt itself, have built-in functionality to help remedy this situation and get things back to normal.

The following tips and tricks will help in most cases. However, they are common remedies that cannot be applied to all different situations. So keep this in mind when trying to solve your own situation.

Fix broken package in Ubuntu

  1. Fix errors with Apt / Apt-Get
  2. Fix error with DPKG
  3. DPKG lock

Fix errors with Apt / Apt-Get

Apt has a few flags that users can use to fix dependencies or packages that are corrupted for any reason during the installation. The most common way to do this is to install a third-party .deb and find out the dependencies are not available. Those dependencies cannot be pushed into place and dpkg will notice that the package is missing. In any case, users can try the following steps.

How to fix broken packages in Ubuntu Picture 1

First, run an update to make sure there are newer versions for the required packages.

 sudo apt update --fix-missing 

Next, users can try to force Apt to find and fix any missing dependencies or broken packages. This tool will actually install any missing packages and repair existing settings.

 sudo apt install -f 

Fix error with DPKG

Another step where errors can arise during package installation is the configuration process. In fact, dpkg is in charge of this part, not Apt, so when a package fails while configuring, dpkg will be the most effective tool to fix.

How to fix broken packages in Ubuntu Picture 2

Start by forcing dpkg to reconfigure all or part of the corrupted package.

 sudo dpkg --configure -a 

If this tool does not solve the problem, users can apply a more robust approach. Let's start by listing packages marked as requiring reinstallation.

 sudo dpkg -l | grep ^.r 

If the package (s) is found to be problematic, the user may force to remove the corrupted packages.

 sudo dpkg --remove --force-remove--reinstreq 

When dpkg completes its work, try to 'clean up' everything with Apt.

 sudo apt clean sudo apt update 

After that, everything will return to the starting point. This does not help regain damaged packages, but at least Apt will work again.

DPKG lock

How to fix broken packages in Ubuntu Picture 3

A rare problem is that the dpkg lock prevents users from doing anything. Whenever trying to use Apt or dpkg, users will get an error stating that an application is ready to use, while in fact it is not. It's easy to delete the lock file that prevents using Apt and go back to doing what is needed. Sometimes these lock files remain in place after an error during the installation process, interrupting the process and preventing the file from being deleted automatically. In this case, do it manually.

 sudo rm /var/lib/apt/lists/lock 

The best solution is to delete the lock in the cache.

 sudo rm /var/cache/apt/archives/lock 

Hopefully, one of the ways to fix the above error will be effective in your case and everything works back to normal on Ubuntu. Remember that the best way to thoroughly handle a situation 'out of reach' is to try to bring things back to the starting point. Don't "try to eat away" or solve problems by adding more things, unless you know exactly what you're doing. Chances are you will make things worse.

Good luck!

See more:

  1. How to fix Ubuntu update errors
  2. How to troubleshoot Ubuntu problems does not start
  3. How to fix errors without sound in Ubuntu
4.1 ★ | 18 Vote

May be interested

  • 11 great LXDE themes for LinuxPhoto of 11 great LXDE themes for Linux
    the default theme that comes with lxde desktop environment is outdated and extremely bland. but don't worry! because this desktop environment is on linux, users can freely change their preferences.
  • How to take a screenshot of the login screen in LinuxPhoto of How to take a screenshot of the login screen in Linux
    there are many screen capture utilities available for linux and most work very well. but strangely, none of these tools have the ability to take a screenshot of the login screen.
  • Instructions for using zforce command on LinuxPhoto of Instructions for using zforce command on Linux
    the gzip command is a popular tool used to compress / decompress files in linux. tipsmake.com presents the basics of this tool in the article: some basic terminal commands in linux mint 11.
  • How to install Composr CMS on Ubuntu 18.04 LTSPhoto of How to install Composr CMS on Ubuntu 18.04 LTS
    composr is a free and open source cms with advanced interactive functions. it is written in php language and uses mariadb to store data.
  • How to install Spotify on LinuxPhoto of How to install Spotify on Linux
    spotify has actually supported linux for a long time. although most distributions do not include this application in the repository for license reasons, it is not really difficult to install this official player on a linux pc.
  • How to fix sources.list file on Kali LinuxPhoto of How to fix sources.list file on Kali Linux
    the sources.list file issue often appears after updating kali linux. today's article will show you how to edit sources.list file on kali linux.