Software & AppsOperating SystemLinux

How To Remove Obsolete Packages After Failed Upgrade on Ubuntu?

Ubuntu 5

In this article, we will guide you through the process of removing obsolete packages after a failed upgrade on Ubuntu. This can be a common issue faced by users, and knowing how to handle it can save you time and prevent potential system issues.

Understanding Obsolete Packages

Obsolete packages are software or applications that were previously required but are no longer necessary for your system’s operation. They might have been installed as dependencies for other packages, or they might be remnants from a previous version of Ubuntu. Over time, these obsolete packages can take up disk space and potentially cause conflicts with newer packages.

Step 1: Opening a Terminal

Firstly, you need to access the terminal. This can be done by pressing Ctrl+Alt+T on your keyboard. The terminal is where you’ll enter the commands to remove the obsolete packages.

Step 2: Completing the Upgrade Process

In the terminal, run the following command:

sudo dpkg --configure -a

This command helps to finish the upgrade process manually and solve any dependency issues that might have caused the upgrade to fail. Here, sudo allows you to run commands with administrative privileges, dpkg is the package manager from Debian (which Ubuntu is based on), and --configure -a configures all packages.

Step 3: Removing Obsolete Packages

After completing the upgrade, you can manually remove the obsolete packages by running the following commands in the terminal:

sudo apt-get update
sudo apt-get autoremove
sudo apt-get clean
  • sudo apt-get update updates your package list, ensuring you have the latest information about what packages need to be upgraded or removed.
  • sudo apt-get autoremove removes packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.
  • sudo apt-get clean clears out the local repository of retrieved package files, freeing up disk space.

Step 4: Removing Remaining Obsolete Packages

If the above commands don’t remove all the obsolete packages, you can use the following command:

sudo dpkg -l | grep "^rc" | awk '{print $2}' | xargs sudo apt-get remove -y --purge

This command lists all packages marked as “rc” (removed but not purged), then removes them using apt-get remove --purge. Here, grep "^rc" filters for packages marked as “rc”, awk '{print $2}' prints the second field (the package name), and xargs sudo apt-get remove -y --purge removes each package.

Step 5: Updating the GRUB Bootloader

Finally, update the GRUB bootloader configuration by running the following command:

sudo update-grub

This command updates the GRUB bootloader with the latest kernel and system information.


By following these steps, you should be able to successfully remove obsolete packages from your Ubuntu system after a failed upgrade. Remember to exercise caution when removing packages and always review the list of packages to be removed before proceeding. If you’re unsure about a package, you can always look it up to understand its purpose.

For more detailed information about Ubuntu’s package management commands, you can refer to the Ubuntu documentation.

What are the risks of removing obsolete packages?

The main risk of removing obsolete packages is accidentally removing packages that are still needed by your system. This can potentially cause system instability or even render your system unusable. It is important to carefully review the list of packages to be removed before proceeding and ensure that you are not removing any critical packages.

How can I check the list of obsolete packages before removing them?

You can check the list of obsolete packages by running the command sudo apt-get autoremove --dry-run. This command will simulate the removal process and show you the list of packages that will be removed without actually removing them. Review this list carefully to ensure that no critical packages are included before proceeding with the actual removal.

Can I reinstall a package that I accidentally removed?

Yes, you can reinstall a package that you accidentally removed. You can use the command sudo apt-get install [package-name] to reinstall a specific package. Make sure to replace [package-name] with the actual name of the package you want to reinstall.

Leave a Comment

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