Linux

How to Fix Broken Packages on Ubuntu?

Dealing with broken packages on your Ubuntu system? Then this guide will help you fix the issue.

The package managers on the Linux system do a great job of simplifying the software installation process. However, a malfunction in the installation process or post-installation scripts and other unexpected issues such as bad internet connection, misconfigured third-party installers, improper removal of packages etc. can lead to a broken package issue.

In this article, I will show you how you can identify broken packages on the Ubuntu system and how you can fix them. Not only that, I will also give you some tips to prevent this issue from happening in the future.

Pre-requisites

  • You’ll need an account with sudo privileges.
  • Ubuntu system.

Identifying Broken Packages

To fix the broken packages issue on Ubuntu, first, you need to identify them. You can do so using either the command-line or graphical method.

Check for broken packages using the Terminal:

You can use the following commands to check the broken packages on your Ubuntu system.

sudo apt-get check
apt-get check command

The apt-get check command will scan the system for any broken dependencies that are required by the installed packages.

sudo dpkg --audit
audit using dpkg command

This dpkg will audit your installed packages and output any warnings or errors which include broken packages.

Check for Broken Packages using Synaptic Package Manager

You can also use the Synaptic package manager to identify broken packages. It is a GUI-based package manager for Ubuntu. It doesn’t come pre-installed on the latest Ubuntu system. However, you can follow this simple guide to install Synaptic package manager on Ubuntu.

To view broken packages:

1. Start the synaptic package manager.

2. Click on the “status” button.

3. Now, select “Broken Dependencies”.

identifying broken packages using synaptic package manager

This will list all the broken packages on your Ubuntu system.

Fixing Broken Packages

Now you have identified the broken packages on your Ubuntu System, it’s time to fix them. Again, you can fix the broken packages on Ubuntu using the terminal or the synaptic package manager.

Fix Broken Packages Using the terminal

To fix this issue through the terminal, you can use the apt and dpkg commands with the appropriate flag:

1. Open the terminal and type the following to reconfigure the dpkg:

dpkg --configure -a

2. Now use the apt command with the “-f” flag to locate the missing packages and install them.

sudo apt install -f
using apt to fix broken install

3. Press Enter to continue with the installation process.

This will solve the broken packages issue on Ubuntu.

Fix Broken Packages using the Synaptic Package Manager

You can also fix the broken packages issue graphically via the Synaptic Package Manager.

1. Open the synaptic package manager through the applications menu.

2. Click on the “Status” button.

3. Select “Broken Dependencies” from the filter options. This will display all broken packages.

4. Right-click on the broken package and select “Mark for Reinstallation”.

fix broken package on Ubuntu by reinstalling it synaptic

5. Click on “Mark” and then the “Apply” button in Synaptic Package Manager to re-install the marked packages.

mark the required changes in synaptic

This will re-install all the broken packages on your Ubuntu system.

Removing Broken Packages from the Ubuntu

If the above-mentioned steps to fix the broken packages issue don’t work for you, then you can try removing the broken packages.

Using the Terminal to remove Broken packages on Ubuntu

1. Reconfigure dpkg using the following command:

sudo dpkg --configure -a

2. Check for any packages that require re-installation.

sudo dpkg -l | grep ^..r

3. Use the “–remove” flag to remove the broken packages. The “–force-remove-reinstreq” flag will remove a package, even if it’s broken and marked to require reinstallation.

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

(Replace “vim” with your package name)

forcefully remove a broken package using dpkg

4. Once you do that, run the following commands:

sudo apt clean
sudo apt update

The first command will clear the local repository of retrieved package files that are left in /var/cache whereas the second will update the repositories.

Remove broken packages using the Synaptic Package Manager

If you are not confident enough to use the terminal, then you can also remove the broken packages through the Synaptic Package Manager.

1. Start the Synaptic Package Manager.

2. Find the broken packages that you wish to remove.

3. Right-click on it and select the “Mark for complete removal” option.

remove broken package using synaptic

4. Click on Apply to remove the selected packages.

confirm removing package using synaptic

This will remove the packages completely from your Ubuntu system.

Tips to Prevent Broken Packages Issue

Follow these best practices to avoid broken packages and other related issues in the future.

1. Keeping your Ubuntu system up-to-date

Keeping the system software updated can help you avoid potential problems created by outdated packages. Use the Aptitude (Apt) or Synaptic to keep the Ubuntu system updated.

2. Using third-party repositories with caution

Third-party repositories can sometimes create conflict with the existing packages on your system, which can lead to the broken packages issue. No doubt, there will be times when you need to use third-party repositories, however, use them with caution.

3. Properly remove installed packages

Improper removal of a package can lead to a broken packages issue. Whenever you wish to remove installed software from your Ubuntu system, do that using the appropriate terminal command or use the synaptic package manager to uninstall software graphically.

Avoid deleting the package files manually from the system or using commands like:

sudo dpkg -P --force-depends <package name>

Although you may be able to delete any package forcefully using this command, it will create dependency issues for other installed packages on the system.

Wrapping Up!

I have shown you the step-by-step process of how to fix the broken packages issue on Ubuntu. If you are planning to use Linux for development, then you’ll face this issue every now and then.

Following the steps mentioned in this article will help most users to fix the issue. However, if you have used any other method to fix the broken packages issue on Ubuntu, do share it in the comments. It will prove helpful to other readers.

If you like this post, then follow CenturyBuzz on Facebook and X (Twitter) for more reviews, tips and tutorials.

Rahul Nair

Rahul is a passionate writer with a deep-rooted love for technology. His articles, tutorials, and guides are crafted with the aim of helping others solve technical problems and kindle their passion for learning. When not busy with the ever-evolving world of technology, he dedicates his time to learning something new every day. Whether it's delving into a new skill, exploring the power of AI, or simply seeking out fresh perspectives, Rahul's commitment to lifelong learning remains unwavering.

Leave a Reply

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

Related Articles

Back to top button