Finding & Removing Orphaned Apt Packages in Ubuntu

When you install software packages (e.g Nginx) in Ubuntu or Debian, the software would most likely depend on other packages to run, so, if the packages that it depends on aren’t installed, it is going to install it.

But if you remove the software package, the dependable packages will not be removed automatically, and that’s where the orphaned term arose from. It basically means the package is no longer needed on your system.

Let’s take a scenario. If you try installing Nginx or any other software packages, Ubuntu will remind you periodically as you use the apt tools, for example:

sudo apt install nginx


Reading package lists... Done
Building dependency tree
Reading state information... Done
<span style="color: #ff4136;">The following packages were automatically installed and are no longer required:
</span>  fakeroot g++ g++-7 gcc gcc-7 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan4
  libatomic1 libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-7-dev
  libgomp1 libitm1 liblsan0 libmpx2 libquadmath0 libstdc++-7-dev libtsan0 libubsan0 linux-libc-dev manpages-dev
Use 'apt autoremove' to remove them.

It is basically telling us the packages were installed as a dependency on other packages and are no required because the software they depend on has been removed. The system now thinks they can safely be removed.

In fact, if you try uninstalling a package, it is still gonna remind you of the orphaned packages, that’s one way to find out packages that aren’t needed anymore.

To remove the orphaned packages, you can use the apt autoremove command as root to remove them.

Another way to remove unused packages is by using aptitude, which gives you tons of flexibility on how you choose to remove the packages…

Find and Remove Unused Packages Using Aptitude

To get started with aptitude, you’ll need to install it:

sudo apt install aptitude

If you recall, the system shows you some packages that are no longer required, which you can automatically remove using the apt autoremove command, what if you would rather not remove a specific package, aptitude to the rescue.

You uncheck the package from automatically installed:

sudo aptitude unmarkauto <packagename>

Once you’ve done that, the package would no longer be a candidate for autoremove and thus, you can use autoremove command to remove the other packages without it removing the one you just unmarked.

As an added alternative, you can use the graphical interface that comes bundled with aptitude to manage packages, to use the graphical interface, you simply run sudo aptitude.

Aptitude gui

You can see how sweet it is to manage packages in aptitude, you can browse packages that are split into different categories. For example, you can go to the installed package, and remove some packages you don’t or you can even unmark multiple packages as automatically installed, and when you use the autoremove command, they are still preserved.

I’ll write more guide on using aptitude, till then.


Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

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