Ubuntu Remove Unused Packages [Command Line and GUI]

Last updated: February 9, 2023 | Linuxopsys

Removing unused packages helps to conserve disk space by freeing up the occupied space and clearing any clutter on the system. Additionally helps reduce security vulnerabilities, as outdated packages may contain security risks.

In this tutorial, we learn how to remove unused packages in Ubuntu / Debian systems.

1. Using apt

The apt package manager provides 3 options to handle unused packages - autoremove, autoclean, and clean.

apt autoremove

When you install a program using apt, by default it installs one or more dependency packages. Later when you remove the program those dependency packages stay on the system. The apt remove command is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed. To safely remove those unused dependency packages, type:

sudo apt autoremove
apt autoremove

apt clean

When you install a package using apt, it downloads the package file first and then installs it. After installation, this file still exists in the /var/cache/apt/archives/ directory. You may only need this file only if you want to reinstall the same version of the package. When you install the newer versions of the package the old package file is still available on the system. You don't need it anymore.

The apt clean command will clean all the downloaded package files from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.

sudo apt autoclean
apt clean

apt autoclean

The apt autoclean clears the same /var/cache/apt/archives but the only difference it removes onyl the files that cannot be downloaded anymore. Both clean and autoclean are safe to run.

sudo apt clean
apt autoclean

2. Using deborphan

Deborphan is a command-line tool for Debian-based systems that help identify orphaned packages. Orphaned are installed packages but are not required by any other packages on the system. This happens when actual applications are removed and then their dependencies packages keep remain.

Deborphan scans the installed packages and identifies those that have no other package depending on them, and can be safely removed to free up disk space.

Deborphan is not installed by default in Ubuntu / Debian, so you will need to install it first.

sudo apt install deborphan

To list all orphaned packages, type:

deborphan
run deborphan command

Now, to remove orphaned packages type:

sudo apt remove $(deborphan)
delete orphaned packages using deborphan

Note that it's always a good idea to check the list of packages before removing them, as deborphan may identify packages that you still need.

3. Using GUI based Tools

Let's check a couple of useful graphical tools which help you to remove unwanted packages and files.

BleachBit

BleachBit is a free, open-source system cleaning software for Windows and Linux. It helps to clear cache, temporary files, and other system junk that can take up valuable disk space. The tool can erase the following types of data:

  • Cache files from web browsers and other applications
  • System log files
  • Thumbnail caches
  • Old backups and log files
  • Old user data and temporary files

Before using BleachBit, you need to install it on your system.

sudo apt install bleachbit

After installing BleachBit, launch it.

sudo bleachbit

When you launch BleachBit, you will see a list of categories that contain various files and packages. You can select the packages you want to remove by checking the boxes next to them.

BleachBit clean packages and files

Some of the common categories that contain unused packages include:

Cache: This category includes cache files from web browsers, package manager, and other applications.

Logs: This category contains logs generated by various applications and services.

Old backups: This category includes old backup files that may be taking up valuable disk space.

Before removing the packages, you can preview the cleaning process by clicking the "Preview" button. This will show you a list of the files and packages that will be removed. Make sure that you are comfortable with the changes before proceeding.

Once you have previewed the cleaning process, click the "Delete" button to remove the selected packages.

Stacer

Stacer is a free and open-source system optimizer and monitoring tool for Ubuntu and other Debian-based Linux distribution. It provides a user-friendly interface for managing various system components, including packages. In this regard, Stacer can help you remove unused packages, freeing up disk space and potentially improving the performance and stability of your system.

Installation

sudo apt install stacer

Now launch the app from the application menu.

In Stacer, go to the "System Cleaner" tab. In the System Cleaner tab, select the option "Select All" at the bottom.

Stacer system cleaner

Stacer will scan your system for unused packages and files using system cleaner.

Scan system cleaner

Select the packages you want to remove and click the "Clean" button. Stacer will prompt you to confirm the removal of the selected packages. Click "Yes" to proceed with the removal. The progress of the removal will be displayed in Stacer. Wait for the process to complete.

Stacer system cleaner results

After the removal, restart your system to ensure that all changes have taken effect and to free up the disk space occupied by the unused packages.

Conclusion

In this tutorial, we learned how to remove unnecessary packages and files on Ubuntu / Debian systems.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

1 Comment

1 thought on “Ubuntu Remove Unused Packages [Command Line and GUI]”

Leave a Comment