Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Clear the Cache in Ubuntu

This guide shows you how to free space on Ubuntu by clearing package cache, temp files, thumbnails and memory cache.

How-To Guides2 min read6 steps

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.

  1. Open a terminal. A terminal is a window where you type commands. On a server, use SSH.
  2. See how much space the cache uses.
    du -sh /var/cache/apt
  3. Remove the downloaded package files.
    sudo apt clean
  4. Remove packages that nothing needs anymore.
    sudo apt autoremove
    Read the list before you press Y.

Step 2: Clear old log files

  1. Check the size of system logs.
    journalctl --disk-usage
  2. 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.

Warning: Be careful with 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 clean and sudo apt autoremove for packages.
  • Use journalctl --vacuum-time=7d for old logs.
  • Remove thumbnails from ~/.cache/thumbnails.
  • Memory cache is normal. Clear it only if needed.