How to Free up Space on Ubuntu (20.04)

How to Free up Space on Ubuntu (20.04)

·

3 min read

Out of Space? Welcome to the club. Time for some space hunt. Here are some techniques that worked for me. You might want to start with the last one, it will save you so much work.

  • Remove all unused packages.
    sudo apt-get autoremove
    
  • Clear the APT cache.

    Check the cache size:

    sudo du -sh /var/cache/apt
    

    Clear cache

    sudo apt-get clean
    
  • Clear systemd journal logs. This freed up a good amount of space.

    Check the space occupied:

    journalctl --disk-usage
    

    Clean out some logs. You might want to read about this: Clearing systemd journal logs in linux. But if you are in dire need of space and have no time, use the command below. It will clear all the logs older than 2 days.

    sudo journalctl --vacuum-time=2d
    
  • Remove older versions of Snap applications Check the space occupied
    du -h /var/lib/snapd/snaps
    
    Create a script file, add the lines below, and save. I saved mine as script.sh on Home directory.
    set -eu
    snap list --all | awk '/disabled/{print $1, $3}' |
      while read snapname revision; do
          snap remove "$snapname" --revision="$revision"
      done
    
    Give the file execute permissions
    chmod 0700 script.sh
    
    Run the script to remove older packages.
    sudo ./script.sh
    
  • Uninstall apps you don't use. Stop saving them for the future! Easy for me to say but this was hard for me. I resorted to deleting everything I haven't used in the past two months, or anything with an online alternative.

  • Install Stacer and let the system cleaner do the work for you. You can search Stacer in ubuntu software or use the command below to install.

    sudo apt install stacer
    

There you have it nice and clean!