How to free up disk space on Ubuntu when your root partition is almost full

Generally, it is a good idea to have a separate root and home partition, so when you decide to try a new Linux distribution or do a clean install, you can reformat the root partition without losing your personal data. With this method a few years back 8 GB was more than enough for the root partition, but now with the advent of Snap, Flatpak and other alternatives, even a 20 GB root partition can run out of space in a few months. Let’s see how to clean up space on a modern Ubuntu-based distribution like Zorin OS or Mint…

How I do a clean reinstall?

With a separate home partition I usually just rename my home folder from /home/myuser to /home/myuser-old before booting from the pendrive. During the install I mark my root partition for format but mount my home partition without the format option checked. After the install I will selectively copy everything I want to keep from /home/myuser-old to the newly created /home/myuser folder and delete the old folder when I do not need it anymore.

I use Zorin OS 16, which installs software from multiple sources. It is not enough to delete the Apt cache anymore, we have to take Snap and Flatpack into consideration too.

Apt

To clean the Apt cache, copy these commands into the terminal:

sudo apt update
sudo apt clean

Snap

To remove old versions of Snap packages, first you need to create a script. Open up a text editor like Gedit or whatever you like and save a file named clean_snap.sh with the following content:

#!/bin/bash
 #Removes old revisions of snaps
 #CLOSE ALL SNAPS BEFORE RUNNING THIS
 set -eu
 LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
     while read snapname revision; do
         snap remove "$snapname" --revision="$revision"
     done

Now make the file executable by issuing this command in the terminal:

chmod +x clean_snap.sh

Now all you need is to run it as root:

sudo ./clean_snap.sh

A big thanks for the original source here: https://www.debugpoint.com/2021/03/clean-up-snap/

Flatpak

Cleaning up Flatpak is pretty simple, just enter this command in the terminal to remove unused packages:

flatpak uninstall --unused

Old kernels

You probably don’t need 10+ kernel versions if the default works when booting up. Issue the following command in the terminal to remove every version except the current, previous and original kernel that your distribution shipped with.

sudo apt autoremove --purge

Everything else

If you still need to get rid of stuff or just want to get better acquainted with your system, give Bleachbit a go.

You can install with the following command:

sudo apt install bleachbit

Related Posts

Sorry, no similar posts found.

3 thoughts on “How to free up disk space on Ubuntu when your root partition is almost full

Leave a Reply

Your email address will not be published. Required fields are marked *