CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > How to > How to clear cache from Ubuntu?

How to clear cache from Ubuntu?

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 2 min read · 0 Comments
Share: in X
git change remote url

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
Step 2: Enter Superuser Mode
Step 3: Clear Cache
Clean local repository
Remove automatically installed packages
Synce the file system

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:

sudo su

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

apt-get autoclean

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

apt-get autoremove

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

Disclaimer

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

Related Posts:

  • How to Solve “systemctl command not found” Error: A…
  • How to Upload File to AWS EC2 Instance From Local Machine?
  • Default Variable Initialization in Java
  • Install MongoDB BI Connector on Ubuntu
  • How to Install Ollama on Windows, Linux, and macOS:…
  • JDBC Best Practices: Writing Robust and Efficient…
Tags:devopsubuntu
Was this article helpful?
← Previous ArticleBitwise and Shift Operator in Java
Next Article →How to remove service from systemd?

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
© 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap