Ubuntu does not clean up after itself. The APT cache keeps every package you downloaded, snap keeps old revisions of every app, the journal grows until it hits a size limit that is far larger than you would pick, and Docker and your projects add gigabytes of their own.
Looking for the everyday steps first (Trash, Downloads, large files, apps you don’t use)? See how to free up disk space on Ubuntu.
Each tool has its own guide when you need the details: Docker, Snap and Flatpak, Android Studio, JetBrains IDEs and VS Code and node_modules and build folders. This page is the short tour: one look and one safe command per tool. Python and AI tools have theirs too: pip, conda and uv caches and AI models from Ollama, LM Studio and Hugging Face.
This guide goes through the places that usually hold the space: a command to see the size, a command to clean it, and what you lose. Start by finding out where the space is:
df -h /
sudo du -xh / --max-depth=1 2>/dev/null | sort -h | tail -10
-x keeps du on the root filesystem. Repeat the second command on the biggest folder to go one level deeper. ncdu (sudo apt install ncdu) does the same interactively.
APT: cache, unused packages and old kernels
sudo apt clean # delete downloaded .deb files
sudo apt autoremove --purge # remove packages nothing needs, with their config
apt clean costs nothing but a re-download if you reinstall a package. Run sudo apt-get -s autoremove first to see the list: autoremove removes only packages installed as dependencies that nothing needs any more, but read it once anyway.
Old kernels are removed by autoremove too, and Ubuntu keeps the running kernel and the one before it. Check which one you are running and which are installed:
uname -r
dpkg -l 'linux-image-*' | grep '^ii'
Never remove the running kernel, and keep one older fallback in case an update does not boot. If /boot is full and apt is stuck, see Ubuntu out of disk space: /boot full and old kernels.
What CleanMate does. The Packages module cleans the APT cache, unused packages and leftover configs with apt-get, and removes extra old kernels while always keeping the running one and a fallback.
Snap: old revisions
Snap keeps two older revisions of every app that was updated, as disabled copies. List them and remove only those:
snap list --all | awk '/disabled/{print $1, $3}' | while read name rev; do
sudo snap remove "$name" --revision="$rev"
done
To stop the pile from coming back, keep fewer revisions (the minimum is 2):
sudo snap set system refresh.retain=2
Removing a disabled revision costs nothing as long as the active one works. Snap’s rollback to the previous version is gone with it.
What CleanMate does. Old Snap revisions are removed with snap remove --revision, only disabled ones. The Maintenance page can set the lasting limits (fewer snap versions, a smaller journal) so they do not pile up again.
The systemd journal
journalctl --disk-usage
sudo journalctl --vacuum-time=7d # keep the last 7 days
sudo journalctl --vacuum-size=500M # or: keep at most 500 MB
You lose old log lines, which matters only when you debug something that happened last month. To set a permanent cap, uncomment and edit SystemMaxUse=500M in /etc/systemd/journald.conf, then run sudo systemctl restart systemd-journald.
Also look at /var/log for big rotated files (ls -lhS /var/log | head), and at /var/crash and coredumpctl for crash dumps you no longer need.
What CleanMate does. The Logs module vacuums the journal to 7 days with journalctl --vacuum, and cleans rotated and oversized logs, crash reports and core dumps.
Docker
docker system df
docker builder prune # build cache
docker image prune # dangling images
docker image prune -a # every image no container uses
docker container prune # stopped containers
docker volume prune # volumes no container uses: can be your data
docker system prune bundles stopped containers, unused networks, dangling images and build cache. Read docker volume ls before you prune volumes: a database you stopped has a volume no running container uses. With Docker 23 or newer, volume prune removes only anonymous volumes unless you add -a.
Images are downloaded again when you need them, which costs time and bandwidth, not data.
What CleanMate does. Images, build cache, containers and volumes are separate items (Podman too). A named volume is marked “may hold data”, and the desktop app lets you pick images and volumes one by one.
Flatpak: unused runtimes
Flatpak keeps runtimes that no installed app needs any more:
flatpak uninstall --unused
It lists what it will remove and asks first. Your apps’ own data lives in ~/.var/app/<app id>; to remove an app together with that data use flatpak uninstall --delete-data <app id>.
What CleanMate does. It cleans the caches of Flatpak apps (each app on its own line) and its Uninstaller removes a Flatpak app and the leftover data in ~/.var/app. It does not run flatpak uninstall --unused today, so keep that one command in your routine.
Thumbnails, caches and node_modules
du -sh ~/.cache ~/.cache/thumbnails
rm -rf ~/.cache/thumbnails/*
Thumbnails are rebuilt when you open a folder. For developer caches:
npm cache clean --force
pnpm store prune
pip cache purge
go clean -cache
And the folders every project carries: find the biggest node_modules and delete the ones of projects you have left alone, npm install brings them back.
find ~/projects -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null | sort -h | tail -20
rm -rf ~/projects/old-project/node_modules
Change ~/projects to where your code lives. cargo clean in a Rust project removes its target/.
What CleanMate does. Thumbnails and stale caches are part of User & App Junk. Developer Junk lists the package caches (npm, Yarn, pnpm, Bun, pip, uv, Go, Cargo, Gradle, Maven and more), and the node_modules, Cargo target/, Python .venv/ and CocoaPods Pods/ of projects idle for 90 days. Build folders are not ticked and go to the Trash. More in node_modules and old build folders.
Do it in one scan
Each command above is small. The work is remembering all of them and checking the sizes first. CleanMate for Ubuntu (free, open source) does this: install it from the PPA, run cm in a terminal or open the desktop app, press Scan, and it lists each item with its real size. You untick what you want to keep, and nothing is removed until you confirm. The developer junk page covers package caches, Docker and stale build folders in detail.
Editors and VMs are covered in JetBrains and VS Code using too much disk space and virtual machines and dev infrastructure tools.
Want your coding agent to do it? See let an AI agent clean your disk.
