8 Best Fixes for Broken Packages in Ubuntu

8 Best Fixes for Broken Packages in Ubuntu

Installing and removing packages on Linux operating systems like Ubuntu is smooth and easy, but it gets more difficult if you get errors due to broken packages.

If you are unable to install or remove a package, this guide is for you and it will work on Ubuntu, Linux Mint, Kali, Fedora, CentOS and other Linux distributions.

Causes of broken packages in Linux operating systems (Ubuntu and others)

  • The package is partially installed
  • Dependency or repository error
  • New update breaks installation
  • Something in the package conflicts with something else on your system
  • The package was removed incorrectly

How to fix broken packages in Ubuntu and Debian based distributions?

  1. Clean package
  2. Reinstall broken Ubuntu packages (APT)
  3. Use DPKG to Force Removal of Broken Packages
  4. Solve blocking problem
  5. Automatic cleaning of broken packages
  6. Fix broken files in recovery mode
  7. Repair broken system package
  8. Try the Synaptic Package Manager

1. Clean the package

If you know exactly which package is causing problems, fixing broken packages in Ubuntu is pretty easy. You can remove the package and clear disk space.

  • Open the Terminal by pressing Ctrl + Alt + T on your keyboard and pressing the Enter key.
  • Start by clearing the package cache with this command:
  • sudo rm -rf /var/cache/apt/archives/[package name]
  • For example, to clear the Chrome package cache files, try the command
  • sudo rm -rf /var/cache/apt/archives/google-chrome-stable_current_amd64.deb
  • Enter your sudo account password
  • After that, free up storage space and then update the repository with the following commands:
  • sudo apt-get autovacuum
  • sudo apt-get update
  • sudo apt-get update

Also, another way to do this is to move the package cache files to temporary files. Then remove the broken package using the Debian Package Manager (dkpg). (The following command moves and removes RVM.)

  • sudo mv /var/lib/dpkg/info/rvm.* /tmp/
  • sudo dpkg –remove –force-remove-reinstreq rvm

2. Reinstall broken Ubuntu (APT) packages

It is not always possible to know which package is broken on your Linux system. So, try this method to have your system check for missing updates, update the list of packages, and then force install the broken packages.

  • Press Ctrl + Alt + T to open the Terminal.
  • Find the missing updates with the command. It will take some time to check for and fix updates.
  • sudo apt – fix missing update
  • When this is done, it’s time to update the list of packages from the available sources.
  • sudo suitable update
  • Now use the -f flag in the following command to force the installation of broken packages. Ubuntu will look for any broken package and force install it.
  • sudo proper install -f

3. Use DPKG to Force Remove Broken Packages

If you encounter a problem when using the APT package management system to remove problematic packages, use the dpkg package management system instead.

This is useful if you need to force uninstall packages. This is because sometimes packages are installed in the root directory.

Open a terminal shell and do the following:

  • Force the dpkg system to reconfigure packages that are unpacked but not configured. As I am trying to configure all packages using the -a flag.
  • sudo dpkg –configure -a
  • Get a list of all packages marked as required by dpkg.
  • sudo dpkg -l | grep ^..p
  • Now that you have a list of required packages, remove any broken packages. Replace [package-name] with the package you want to remove.
  • sudo dpkg –remove –force-remove-reinstreq [package name]
  • Clean up the package.
  • Sudo aptly clean
  • Update the list of packages from available sources
  • sudo suitable update
  • sudo apt update – fix missing update
  • Run the command below to see which packages have been installed.
  • $ sudo apt-get install -f

4. Solve the lock problem

The dpkg blocking problem is not common, but it prevents you from doing anything. You can access the apt and dpkg package management systems.

Whenever you do this, you will get an error that the file is being used by another file or tool.

The reason for this problem is that some packages are saved to the file system as an archive during installation. They show errors when you try to remove them.

Usually, when you remove something from your Ubuntu system, all of its plugins and dependency files are also removed. But some files don’t work for the above reason and cause problems.

Get root access and delete problematic files:

  • sudo rm /var/lib/apt/lists/lock
  • sudo rm /var/cache/apt/archives/lock

5. Automatic cleaning of broken packages

This method does not remove broken Ubuntu packages, instead it cleans up temporary files left behind by packages after removal.

Many packages leave some of their files on your file system when uninstalled, so if the user decides to install the application again, the process will be faster. We will clean these files.

  • Clean up unused space and wipe cache files
  • sudo apt-get autovacuum
  • sudo apt-clean
  • Remove unnecessary files and dependency data using root access and the command below.
  • sudo apt-get automatic removal
  • After removal, update the list of installed packages
  • sudo apt-get update

6. Fix Broken Files in Recovery Mode

This is an effective method to repair broken packages in Ubuntu and is not commonly used. It doesn’t technically fix corrupted files, but does a repair that also solves the problem of corrupted packages. Duplicate the following steps:

  • To enter recovery mode, turn on your Ubuntu system.
  • When you see the manufacturer’s logo, immediately press and hold the Shift key on your keyboard until some options appear on a black screen (BIOS).
  • Select “Advanced options for Ubuntu”.
  • Then select “Ubuntu with Linux……. (Recovery Mode)’.
  • When the recovery menu appears, select dpkg and press Enter.
  • It will ask you to remount your filesystem in read/write mode. Select Yes.
  • After the process completes, it can request an update if one is available. Enter yN to continue.

7. Repair broken system package

The Software Updater is responsible for updating your Ubuntu system. Any dependency or system error can corrupt the system packages, preventing the software update application from working properly.

To get rid of this error, clear the system cache and clean up the file system.

  • sudo apt-clean
  • sudo apt-get install -f

8. Try Synaptic Package Manager

It is an easy to use GUI package manager that can install, remove, update and fix broken Ubuntu packages.

To install the Synaptic package manager, use the following commands, which require root access:

  • sudo apt-get update
  • sudo apt-get install synaptic
  • After confirmation, press Y and press the Enter key.
  • Once installed, launch it by clicking “Actions”, typing “synaptic package manager”and opening the app.
  • Mark the package as broken.
  • Then click “Edit”in the menu bar and select “Fix broken packages”.
  • After restoring the package, use any of the above methods to remove the package.

Fix broken packages on Fedora, CentOS, and other Red Hat Enterprises Linux (RHEL)

Usually yum and dnf do a good job of keeping packages clean on RHEL operating systems, but some applications still break packages.

  • For rpm based systems, use the following command.
  • sudo rpm -Va
  • This will give you a list of installed files in the rpm database. After that, you can check for suspicious packages and apply the below command.
  • sudo dnf -update reinstall [package name]
  • The above command will set the metadata as expired and may help you find broken dependencies with this package and suggest using the –skip-broken flag.

How to avoid broken packages in Ubuntu and Debian based distributions?

Fixing broken packages in Ubuntu takes time, so it’s best to prevent this in advance by cleaning up and deleting the software repository files you’ve removed.

  • Open Software & Updates.
  • Click the “Other Software”tab. It will have a list of repositories. Choose any to delete.

Conclusion

Finding and repairing or removing broken packages in Ubuntu is a little more difficult, but with the help of the various methods above, you can choose the right one for you and keep your Ubuntu system clean and error-free.

Leave a Reply

Your email address will not be published. Required fields are marked *