Ubuntu is a well-known and top-priority Debain-based operating system for professionals and beginners from all over the world. It comes with a bundle of tools and packages that can be easily installed, removed, updated, and upgraded using its default package manager, “apt”.
An apt is the “Advanced Packaging Tool” that uses different keywords to perform useful tasks like “clean”, “remove”, “purge”, “autoremove”, and so on.
This post will illustrate the objective and usage of the “clean”, “autoclean”, and “autoremove” combined and separately.
- apt clean
- apt autoclean
- apt autoremove
- apt clean, apt autoclean, and apt autoremove Combined
How to Use the “clean” Option?
The “apt clean” command cleans the system cache by removing unnecessary .deb package files from the local repository “/var/cache/apt/archives”. These files are no longer required and only take the extra space on the system.
Run the “apt clean” command to clear the cache directory:
$ sudo apt clean
The command executed successfully, and the cache has been cleared. It is good to clean the system on a daily basis to free up the occupied space.
Show the Directories Location
The “apt clean” supports the “–dry-run” option that displays the directory from where the files will be deleted:
$ sudo apt clean --dry-run
The “Del” keyword shows that the packages will be deleted from the absolute path of the directories shown in front of it.
How to Use the “autoclean” Option?
The “autoclean” is similar to the “clean” command but with limited functionality. It removes the packages that are no longer required but still present in the system. In simple words, it removes outdated and obsolete packages from the system cache that can not be downloaded in the future.
Execute the “autoclean” command and see the output:
$ sudo apt autoclean
How to Use the “autoremove” Option?
The “autoremove” command removes the installation files of packages that are no longer required, along with their additional dependencies. It is recommended to run the “autoremove” command after the uninstallation of packages.
In this scenario, an application “teamviewer” is removed using “autoremove” for the removal of Teamviewer and its dependencies, too:
$ sudo apt autoremove teamviewer
The ”teamviewer” has been removed from the system.
How to Use apt clean, autoclean, and autoremove Combined?
Apart from executing the above three commands one be one, The user can also execute them combined as per requirements.
Using “autoremove” and “autoclean”
Use the “&&” logic “AND” operator to execute the “autoremove” and “autoclean” commands.
The combination of these two commands will first clean the system cache and then additional dependencies of the unneeded packages:
$ sudo apt autoremove && sudo apt autoclean
Both the task have been performed successfully.
Using “autoclean” and “clean”
To delete the obsolete packages and clean the system cache directory, specify the “clean” and “autoclean” commands one after the other in this way:
$ sudo apt autoclean && sudo apt clean
The “clean” command executed successfully without showing output because there are no files in the cache directory. On the other hand, the “autoclean” also checked the newer versions of packages.
Using “autoclean”, “clean”, and “autoremove”
The user can also execute the above three commands simultaneously to clean up the system cache, additional dependencies, and outdated versions of packages:
$ sudo apt clean && sudo apt autoclean && sudo apt autoremove
The output shows the successful completion of “clean”, “autoclean”, and “autoremove” command.
In Ubuntu, the “clean” removes the cache files located in the “/var/cache/apt/archives” local storage. The “autoclean” removes option checks the packages that have newer versions and removes their outdated versions. The “autoremove” deletes the unnecessary packages and the additional dependencies associated with them.
This post has provided a detailed view of how to use the apt “clean”, “autoclean”, and “autoremove” combined and separately.