Clean Up Unwanted APT Packages in Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

New Linux users often install a lot of unnecessary APT packages that they might rarely use in the future. Also, a few bulky distributions come with many pre-installed APT packages.

When the Linux system is running low on disk space, it becomes necessary to clean the APT packages to free up some space, as they can cause performance issues and even prevent the system from booting properly.

There are several ways to find the APT packages that are taking up the most space on your Debian or Ubuntu system; however, we will only cover two of them in this article.

Tutorial Details

DescriptionList and Remove the Largest APT Packages in Linux
Difficulty LevelLow
Root or Sudo PrivilegesYes
OS CompatibilityUbuntu, Debian, Linux Mint, Pop!_OS, etc
Prerequisitesdpkg-query, dpigs, sort, head
Internet RequiredYes

Find the Largest APT Packages Size Without External Tools

The simplest way to find the largest APT packages that occupy the most space in Linux is by using the “dpkg-query” command along with the “sort” and “head” commands.

1. First, use the dpkg-query command to list all the installed packages and their sizes, and redirect the output to a text file:

$ dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' > package-sizes.txt

2. Then use the sort command to sort the text file by the installed size in descending order:

$ sort -nr package-sizes.txt > sorted-package-sizes.txt

3. Lastly, use the head command to list the top 10 largest APT packages:

$ head -n 10 sorted-package-sizes.txt

The following is an output of all the above-mentioned commands:

Finding the APT packages that occupy the most space without an external tool

As you can see from the above output, it displays the top ten largest APT packages as well as their installed size (in bytes) on your system.

If you want to display the sizes in human-readable formats (like in MB or GB), you can pipe the output to the numfmt command, like this:

$ dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -nr | numfmt --to=iec-i --suffix=B --padding=7 --field=1 | head -n 10

Output:

Print the APT package size in a human-readable format

As you can see, all the above methods require a solid understanding of the Linux command-line, which can be a significant burden if you are a regular user who rarely uses Linux.

In that case, you can use the external command-line utility that will be talked about in the next section.

Find the Largest APT Packages Size Using Dpigs Command

The dpigs is a Linux external command-line utility that comes as part of the “debian-goodies” package. Using this command-line utility, you can quickly find the ten largest APT packages along with their sizes without having to type long command-line syntax.

But first, use the following command to install this utility on your Linux system:

$ sudo apt install debian-goodies

After the installation is done, you can use the dpigs command right away to get a list of the top 10 largest APT packages on your Linux system.

$ dpigs

Output:

Output of the dpigs command

This command’s default output is a list of the 10 largest APT packages and their sizes in bytes. This output can be changed by using these command options.

The following is a list of all known options supported by this command:

OptionsDescription
-n=[N]Display the number of “[N]” largest packages in your system (by default, 10).
-sUse status-file instead of the default dpkg status file.
-SDisplay the largest source packages of binary packages installed in your system.
-HDisplay the package sizes in a human-readable format.
-hDisplay the help section.

Check Disk Space Usage

Now, it’s not always required to remove the installed APT packages unless you are sure they are occupying a large chunk of your disk space.

To check your existing disk space capacity and the occupied and available disk space, execute the following command.

$ df -H

Output:

Checking the disk space

As you can see from the above picture, I have enough free disk space in my system, which might not be the case in your case. So, you can remove or uninstall the unwanted APT packages from your system by following the next section.

Removing or Uninstalling Unwanted APT Packages

Once you identify the packages eating up a large chunk of your disk space, you can kick them out using the APT package manager, as shown.

$ sudo apt remove package-name

Also, don’t forget to use the following command to remove any dependencies or libraries that are no longer needed by any installed packages.

$ sudo apt autoremove

So, here comes the end of this article.

I hope you found the largest APT package in your system and easily removed it by following this article.

However, if you have any questions or queries related to this article, then feel free to ask them in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.