How to Clean Unused Flatpak Runtimes and Packages to Free Disk Space in Ubuntu

Flatpak has become one of the most reliable package formats for Linux desktops, providing sandboxed, distribution-independent applications across Ubuntu and its derivatives. Because Flatpak apps package dependencies inside unified containers, they avoid software library conflicts and ensure you always have access to the latest application releases.

However, this architecture comes with a distinct storage trade-off. Over months of installing, updating, and removing applications, older versions of runtime environments (such as GNOME, KDE, and Mesa graphics runtimes) remain stored on your system drive. If left unmanaged, these orphaned Flatpak dependencies can quietly consume 10 to 30 gigabytes of valuable storage in your /var/lib/flatpak partition.

Why Unused Flatpak Runtimes Accumulate

When you install a Flatpak application (like Spotify, LibreOffice, or OBS Studio), it requires a specific base runtime branch—for example, org.gnome.Platform//45. When the application updates to version 46 or when you uninstall the app altogether, Flatpak retains the older version 45 runtime by default in case another software package needs it in the future.

Because Flatpak prioritises application stability over aggressive disk reclamation, it will not automatically purge outdated runtime branches unless you explicitly request maintenance. Learning how to clean these orphaned components restores substantial disk capacity within seconds.

Checking Flatpak Disk Usage on Ubuntu

Before purging data, audit how much space Flatpak is currently occupying on your system:

flatpak list --app --columns=name,application,size
flatpak list --runtime --columns=name,application,branch,size

You can also check the total size of the system-wide Flatpak storage directory directly via Terminal:

du -sh /var/lib/flatpak/

If you have installed Flatpak packages under your personal user profile, check user storage as well:

du -sh ~/.local/share/flatpak/

Removing Unused Flatpak Runtimes with a Single Command

Flatpak includes a native garbage collection utility designed specifically to locate and delete orphaned dependencies. Open your Terminal (Ctrl + Alt + T) and execute:

flatpak uninstall --unused

Terminal will scan your installed applications and present a list of every runtime, SDK, and locale pack that is no longer linked to an existing app. You will see a summary detailing the exact packages to be removed along with the total disk space that will be reclaimed.

Type y and press Enter to confirm the deletion. Flatpak will systematically remove the obsolete runtimes without touching any of your active software or personal documents.

Clearing Flatpak Cache and Build Artifacts

In addition to runtimes, Flatpak stores downloaded transaction archives and repository cache files that can be safely flushed:

  1. Remove user-level Flatpak repository caches:
    rm -rf ~/.cache/flatpak/*
  2. Remove leftover app data from previously uninstalled applications:
    rm -rf ~/.var/app/*

    Note: Only delete directories inside ~/.var/app/ corresponding to applications you have permanently uninstalled, as active configuration settings and game saves reside in these subfolders.

Automating Flatpak Maintenance with systemd

Rather than remembering to execute cleanup commands manually every month, you can automate this maintenance using a simple systemd timer on Ubuntu:

  1. Create a maintenance service unit:
    sudo nano /etc/systemd/system/flatpak-cleanup.service
  2. Paste the following service definition:
    [Unit]
    Description=Clean Unused Flatpak Runtimes
    After=network.target
    
    [Service]
    Type=oneshot
    ExecStart=/usr/bin/flatpak uninstall --unused -y
  3. Create the corresponding weekly timer:
    sudo nano /etc/systemd/system/flatpak-cleanup.timer
  4. Add the timer schedule:
    [Unit]
    Description=Run Flatpak Cleanup Weekly
    
    [Timer]
    OnCalendar=weekly
    Persistent=true
    
    [Install]
    WantedBy=timers.target
  5. Enable and activate the timer:
    sudo systemctl daemon-reload
    sudo systemctl enable --now flatpak-cleanup.timer

Verification and Health Check

After completing cleanup, run flatpak list again or check your disk free space using df -h /. You will find that system responsiveness remains completely intact while reclaiming substantial gigabytes of high-speed SSD storage.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.