In Ubuntu, clearing cache can help improve system performance and free up memory. Whether we’re experiencing sluggishness or just want to keep our system running smoothly, clearing the cache is a good practice. In this guide, we’ll walk through the process I use to clear cache from Ubuntu step by step.
Table of Contents
Step 1: Open Terminal
First, we need to open a terminal window. We can do this by searching for “Terminal” in the Ubuntu dash or by pressing Ctrl+Alt+T.
Step 2: Enter Superuser Mode
To execute commands with administrative privileges, we need to enter superuser mode.
Type the following command and press Enter:
We’ll be prompted to enter your password if not already logged-in with super user. After entering the password we’ll have superuser privileges.
Step 3: Clear Cache
To clear cache I normally do following three commands to clear cache from Ubuntu. These are:
Clean local repository
The above command is used to clean up the local repository of retrieved package files that are no longer downloadable. When we install packages using
apt-get, these packages are stored in a cache on our system.
Over time, these cached files can accumulate and take up disk space. The
autoclean option removes any package files from the cache that can no longer be downloaded, meaning they are obsolete or unnecessary. However, it retains packages needed for future installations.
Remove automatically installed packages
This command is used to remove packages that were automatically installed as dependencies but are no longer required by any other installed package. When we install a package, it may depend on other packages to function properly. These dependent packages are called dependencies.
Sometimes, when we remove a package, its dependencies are no longer needed by any other installed package. The
autoremove option removes these orphaned dependencies, freeing up disk space and keeping our system tidy by removing unnecessary packages.
Synce the file system
The following command syncs the file system and then drops the cache, freeing up memory.
sync; echo 3 > /proc/sys/vm/drop_caches
DisclaimerMost of the time I use these three commands to clear cache and nothing has happened to my machine. I feel safe to use these commands but I always warn people when I advised them to do cleanup things. This is just warning and I am not responsible for any loss.