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.
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
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.
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.