Every install and upgrade leaves something behind: libraries pulled in as dependencies, old kernels and downloaded .deb files. On small cloud servers that can fill /boot or the root disk. Ubuntu’s package manager can clean it up safely.
Step 1 – Check what will be removed
df -h /nsudo apt autoremove u002du002ddry-runRead the list. It should contain only packages that were installed automatically and are no longer needed by anything.
Step 2 – Remove unused packages
sudo apt autoremove u002du002dpurge--purge also removes their leftover configuration files. Confirm with Y.
Step 3 – Clear the package cache
sudo apt cleanThis deletes downloaded installers in /var/cache/apt/archives; apt downloads them again if ever needed.
Step 4 – Optional: shrink old logs
journalctl u002du002ddisk-usagensudo journalctl u002du002dvacuum-time=14dStep 5 – See what you saved
df -h /Read before you confirm
If autoremove proposes removing something you use (for example after you uninstalled a meta-package), mark it as manually installed first: sudo apt-mark manual <package>. On shared servers, review the list carefully – removing a library another site depends on breaks it.
Make it routine
Run sudo apt update && sudo apt upgrade && sudo apt autoremove --purge during regular maintenance, or put it in a script with logging.

