motorscript.com

Cleaning up Ubuntu Server

Published:
An Ubuntu server instance can be cleaned by removing some unwanted packages and disabling services. This saves some disk space and also frees up memory.

Cleanup unnecessary packages

sudo apt purge --auto-remove snapd ubuntu-core-launcher squashfs-tools friendly-recovery ureadahead apport at
Very few server instances utilize these packages. Make sure you don't need them before removing them.

Remove unattended upgrades [CAUTION]

sudo apt purge --auto-remove unattended-upgrades
sudo systemctl disable apt-daily-upgrade.timer
sudo systemctl mask apt-daily-upgrade.service
sudo systemctl disable apt-daily.timer
sudo systemctl mask apt-daily.service
This removes the unattended-upgrades package and the associated services which are reponsible for automatically updating packages in the system. Although removing this package saves disk space and also removes a services running in the background, this is not recommended. You can rather configure unattended-upgrades to install just the security updates.

Other unwanted services

service --status-all
Use the above command to list all services running in your server. Disable the services you don't need.

Remove orphan packages

sudo apt autoremove --purge
This removes packages required as dependencies of previously installed packages which have been removed now.