How to Fix Broken Packages in Ubuntu

Fix Package Errors on Ubuntu

Apt, Ubuntu’s package manager, is among the most powerful and intuitive, but that doesn’t mean that things can’t go wrong. Occasionally, a package install goes wrong on Ubuntu, and you’re left to pick up the pieces. It’s a good thing Ubuntu’s package utilities, including Apt itself, have built-in functionality to help remedy the situation and get things back to normal.

These tips and tricks should help you get unstuck in most instances. They’re all fairly universal, but every situation is different, so keep that in mind when trying to debug your own situation.

With Apt/Apt-Get

Apt has a couple of flags that you can use in order to fix missing dependencies or packages that broke for one reason or another during install. A common use here would be installing a third-party .deb and finding that it had dependencies you didn’t know about. Those dependencies probably won’t be pulled in on their own, and dpkg will complain that the package is missing in them. In any case, you can try these steps.

Ubuntu Apt Fix Missing

First, run an update to make sure that there aren’t newer versions of the required packages.

Next, you can try forcing Apt to look for and correct any missing dependencies or broken packages. This will actually install any missing packages and repair existing installs.


Another place where error can pop up in package installations is the configuration process. Behind the scenes, dpkg is taking care of this part, not Apt, so it would stand to reason that when a package fails during configuration, dpkg is the tool to turn to in order to fix it.

Ubuntu DPKG Reconfigure

Start by trying to force dpkg to reconfigure any broken or partially configured packages.

If that doesn’t solve the problem, you can take a more forceful approach. Start by listing any packages that dpkg marked as requiring a reinstall.

You should see the problematic package(s) there. As long as there’s nothing that seems not to belong there, you can force-remove the broken packages.

When dpkg is done, try to clean up with Apt.

With any luck that’ll get you back to where you started. It won’t get you the broken packages that you tried to install, but at least Apt will be functional again.

Permanent DPKG Lock

Remove Package Lock on Ubuntu

There’s a less common issue with ridiculous dpkg locks preventing you from doing anything. Every time you try to use Apt or dpkg, you get an error saying another application already is … when it isn’t. It’s actually easy to delete the lock file preventing you from using Apt and get back to doing what you need to. Sometimes these lock files remain in place after an error occurs in an install, derailing the process and preventing the file from being removed automatically. In this case, you’ll need to do it yourself.

For good measure, delete the lock in cache.


Hopefully, one of these fixes worked for you, and you’re back working on Ubuntu normally. Remember that the best way to handle a totally out-of-hand situation is to try to return to the way it was before. Don’t try to power through and add more things to solve a breakage by adding more things, unless you know exactly what you’re doing. Chances are you’ll end up with a tangled mess of broken things that’ll be harder to sort out.


  1. Great article. Broken packages can be a pain to fix and this gives some good advice. My favorite is “sudo dpkg –configure -a” to fix a broken package. As for the lock I usually reboot, and that has fixed it, but I did not know about the rm lock commands.

  2. Very interesting, however:

    sudo dpkg –remove –force-remove–reinstreq
    dpkg: error: unknown force/refuse option `remove–reinstreq’

  3. What’s the deal here? Everything I try on the 18.04.02lts system I just installed does not match anything people are explaining online. It’s as if it’s a different OS. It’s the desktop version.

    For instance
    sudo apt install -f
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    0 upgraded, 0 newly installed, 0 to remove and 253 not upgraded.

    Or how about
    sudo dpkg –configure -a
    dpkg: error: need an action option

    The options people list don’t work, the setup system does not contain the tabs that people show.


    I’ve set up lots of systems. the actual software does not match all the help and examples.

  4. ok every broken package is fixed exept nvidia xserver and nvidia visual profiler please help

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.