What is cache?
Cache is a store of temporary files. Ubuntu saves them to work faster. Over time they take space. Some are safe to remove. This guide covers the safe ones. Sudo means "run this command as the admin". You need it for most steps.
The steps work on Ubuntu 18.04, 20.04, 22.04 and newer. Older versions work in a similar way.
Step 1: Clear the package cache
When you install software with apt, Ubuntu keeps the downloaded files.
- Open a terminal. A terminal is a window where you type commands. On a server, use SSH.
- See how much space the cache uses.
du -sh /var/cache/apt - Remove the downloaded package files.
sudo apt clean - Remove packages that nothing needs anymore.
Read the list before you presssudo apt autoremoveY.
Step 2: Clear old log files
- Check the size of system logs.
journalctl --disk-usage - Keep only the last 7 days.
sudo journalctl --vacuum-time=7d
Step 3: Clear user cache and thumbnails
If you use Ubuntu with a desktop, clear picture previews.
rm -rf ~/.cache/thumbnails/*
This removes saved thumbnails. Ubuntu rebuilds them when needed.
rm -rf. It deletes files with no undo. Check the path twice before you press Enter.Step 4: Clear the memory cache
Ubuntu keeps recent files in RAM. This is normal and helps speed. You rarely need to clear it. If you want to, type these.
sync
echo 3 | sudo tee /proc/sys/vm/drop_caches
The first line saves pending data. The second drops the memory cache.
Step 5: Clean the browser cache
Firefox and Chrome keep their own cache. Clear it from the browser's privacy settings.
Quick recap
- Use
sudo apt cleanandsudo apt autoremovefor packages. - Use
journalctl --vacuum-time=7dfor old logs. - Remove thumbnails from
~/.cache/thumbnails. - Memory cache is normal. Clear it only if needed.