Google Cloud

Simple Ways to Free Up Space in Ubuntu Linux

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Ever running out of disk space in your Ubuntu server or system, you can follow the below simple ways to free up space and clean your Ubuntu.

In thins guide you are going to learn how to clean up cache, old kernels, remove unused packages, journal logs.

Prerequisites

Access to server or system with root user or a user with sudo access.

Step 1: Remove APT Cache

Ubuntu keeps a cache of the installed packages which are downloaded or installed earlier even after uninstallation. You can see the cache files in this location /var/cache/apt

To check the disk space consumed you can use the following command.

sudo du -csh /var/cache/apt

Your will get an output that shows the space used by the cache folder.

Output
103M /var/cache/apt
103M total

Now you can clean this cache using the following command.

sudo apt-get clean

This command will clean up the entire cache which frees up more space.

If you wish to clean up only the outdated packages, you can use the following command.

sudo apt-get autoclean

Step 2: Clean Journal Logs

Each Linux disto has their own logging system to investigate what is going on in the system. You will have all logging data related to kernel or any other services.

Over time these logs consume more space. You can check the log size using the following command.

sudo journalctl --disk-usage

You can clear these logs which are older than certain days using the following command.

sudo journalctl --vacuum-time=2d

This command will delete all logs that are older than 2 days.

Step 3: Clean Up unused Packages

If you have packages that are not used you can use the following command to remove these packages.

sudo apt-get remove package_name

Step 4: Remove Old Kernels

You can remove the kernels that are no longer needed and that are installed from Ubuntu archive while system updates using the following command.

sudo apt-get autoremove --purge

This command will not remove the kernels that are installed manually.

Conclusion

Now you have learned how to clean up your Ubuntu server or system by cleaning the journal logs, cache, unused packages, old kernels.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

3 Comments

  1. When I run “apt-get autoremove –purge”, it increases disk utilz by about 80M which is almost 5% of my disk. From du command, I don’t see any directories that have increased in size. How would you explain the increase in utilization?

  2. @Kha – you have less than 2G hard drive?

    I’m wondering if just running apt updated some other packages for you and that would be the increase.

    If you’re using Docker you should also try a:
    docker prune

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.