I have an Ubuntu server with the default package list installed. I'd like to uninstall everything that isn’t nginx, its dependencies, and any other packages required to boot to a tty and run nginx.

Is there a way to do this without manually discerning which packages to remove?

Aside: my reason to do this is so the system has as few tools installed as possible in case of exploits in nginx etc.

Edit: I will also need sshd, and sudo… maybe a good answer will point out other things I will likely need.


1 Answer 1


The system wouldn't allow you to remove sudo without a fight, just like it wouldn't let you remove your kernel or the apt tools themselves. One problem is that your question mixes two problems: (1) what is the set of packages that are minimally required for nginx as apt dependencies and (2) what is a sane minimal set of packages for a healthy working system.

As an example, nginx probably may not depend in any libapt sense on sshd, but you don't want to remove ssh from a remote server. I actually think @tigran's answer is safest and quickest. You can install a minimal system in minutes, and this question has already been here a half-hour.

Other than that, I would suggest that aptitude has very powerful search and matching options. You could probably craft a command line like this:

aptitude purge $(aptitude search <not-depended-on-by-nginx> and <not-essential>)

But again, getting such a command just right might very well take longer than installing a minimal system and setting it running.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.