Linux

How to Clear Ubuntu Cache: Free Up Space and Speed Up Your System

In this guide, you'll learn how to safely clear various types of cache in Ubuntu to free up disk space and keep your system running optimally.

Updated at February 16, 2026
10-15 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04Ubuntu 22.04Ubuntu 24.04

Introduction / Why This Is Needed

Cache in Ubuntu consists of temporary files that the system and applications save to speed up operations. Over time, the cache (especially APT cache and systemd journals) can occupy gigabytes of disk space. Regular cleanup helps:

  • Free up space on the system partition, which is critical for SSDs with small capacity.
  • Speed up the system, as some services (like journald) stop lagging when logs become excessively large.
  • Maintain order by avoiding the accumulation of unnecessary data.

This guide is suitable for Ubuntu 20.04 and newer. All commands work on a standard installation without additional software.

Requirements / Preparation

Before starting, ensure:

  1. You have terminal access (Ctrl+Alt+T) and superuser privileges (ability to run sudo).
  2. Your system is Ubuntu 20.04, 22.04, 24.04 or a derivative (Kubuntu, Xubuntu).
  3. You understand what you are deleting: the commands below are safe, but careless use of rm -rf can lead to data loss.

⚠️ Important: If you are working on a server or a production system, back up important data before performing a mass cleanup.

Step-by-Step Instructions

Step 1: Check Current Disk Usage

First, determine where exactly space is lacking. This will help assess the impact of the cleanup.

# Overall disk partition usage
df -h

# Analysis of large directories in root (may take some time)
sudo du -sh /* 2>/dev/null | sort -rh | head -20

The du command will show the top 20 largest directories. Pay attention to /var (logs, caches) and /home (user data).

Step 2: Clean the APT Cache

The APT cache stores downloaded .deb package files. After installation, they are usually no longer needed.

# Remove ALL downloaded .deb files (most aggressive option)
sudo apt clean

# Remove only obsolete files (those no longer available in repositories)
sudo apt autoclean

# Additionally: remove unnecessary dependencies (not cache, but also frees space)
sudo apt autoremove --purge

💡 Tip: If you frequently reinstall the same packages, keep the cache (do not run apt clean). However, for most users, regular cleanup is beneficial.

Step 3: Clean systemd Journals

The systemd-journal can grow to gigabytes, especially during heavy system activity.

# Keep journals only for the last 3 days (recommended)
sudo journalctl --vacuum-time=3d

# Or limit the size of remaining journals (e.g., 100 MB)
sudo journalctl --vacuum-size=100M

# Check current journal size
sudo journalctl --disk-usage

Configure permanent limits via /etc/systemd/journald.conf (parameters SystemMaxUse, SystemKeepFree).

Step 4: Remove Temporary Files

Temporary directories /tmp and /var/tmp often contain leftovers from completed processes.

# Clean /tmp (files older than 10 days are automatically removed on reboot, but can be cleared now)
sudo rm -rf /tmp/* /var/tmp/*

# Safer option: delete only old files (older than 7 days)
sudo find /tmp -type f -atime +7 -delete
sudo find /var/tmp -type f -atime +7 -delete

⚠️ Important: Do not delete files in /tmp if processes are currently using them (e.g., during software installation). It's best to do this during off-peak hours.

Step 5: Optional: Browser and User Data Cache Cleanup

If you still need more space, check your home directory:

# Firefox/Chrome cache (replace username with your actual username)
du -sh /home/username/.cache/

# Clear Firefox cache (close the browser first!)
rm -rf /home/username/.cache/mozilla/firefox/*.default/cache2/

# Clear Chrome/Chromium cache
rm -rf /home/username/.cache/google-chrome/Default/Cache/
rm -rf /home/username/.cache/chromium/Default/Cache/

Verify the Result

After completing the steps, check free space again:

df -h

Compare the values before and after. Typically, cleaning APT and systemd journals frees 200 MB to 2 GB of space, depending on system activity.

Possible Issues

IssueSolution
Permission denied when running commandsAdd sudo at the beginning or switch to root (sudo -i).
System didn't free space after cleanupCheck if files are in use by other processes (`sudo lsof
System became slower after journald cleanupThis is temporary: systemd rebuilds indexes. The effect should subside within a few minutes.
Accidentally deleted an important file from /tmpRestore from backup or restart the service that used it (often files in /tmp can simply be deleted).

If you encounter regular disk space shortages, consider:

  1. Expanding the /var partition or adding a new disk.
  2. Configuring automatic log rotation (logrotate for classic logs, journald for systemd).
  3. Moving home directories to a separate partition.

This guide covers the main sources of "junk" in Ubuntu. For more specific cases (Docker images, Flatpak/Snap cache), consult the documentation for the respective package manager.

F.A.Q.

Can I clear all cache without sorting to save time?
What to do if the system becomes slower after clearing the cache?
How to set up automatic cache cleanup in Ubuntu?
Is it safe to delete APT cache? Will it break installed packages?

Hints

Check current disk usage
Clear APT cache
Clear systemd journals
Remove temporary files
Check the result
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community