Zum Inhalt springen
Ubuntu / Linux

Free Up Disk Space on Ubuntu: Clean Unused Packages with apt autoremove

Run sudo apt autoremove --purge, then sudo apt clean. Check the result with df -h.

Getestet mit Ubuntu 24.04 LTS, 22.04 LTS

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

Terminal
df -h /nsudo apt autoremove u002du002ddry-run

Read the list. It should contain only packages that were installed automatically and are no longer needed by anything.

Step 2 – Remove unused packages

Terminal
sudo apt autoremove u002du002dpurge

--purge also removes their leftover configuration files. Confirm with Y.

Step 3 – Clear the package cache

Terminal
sudo apt clean

This deletes downloaded installers in /var/cache/apt/archives; apt downloads them again if ever needed.

Step 4 – Optional: shrink old logs

Terminal
journalctl u002du002ddisk-usagensudo journalctl u002du002dvacuum-time=14d

Step 5 – See what you saved

Terminal
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.

Inder Kochar

Geschrieben von

Inder Kochar

System- & Netzwerkingenieur – Ich schreibe die Lösungen auf, die ich bei Kunden einsetze – getestet auf echten Systemen. Hängen Sie an etwas Ähnlichem fest?

Weiterlesen

Stellen Sie eine Frage oder teilen Sie Ihre Lösung

Ihre E-Mail-Adresse wird nicht veröffentlicht. Kommentare werden moderiert – bitte beim Thema bleiben.