As a Manjaro user, we are using pacman package manager all the time to install various packages. It’s fun to install packages using pacman because it is a fast and reliable package manager.
However, after installing the packages, pacman does leave cache files of dependencies and packages that you installed. With the passed of time, this cache will become piled up and take a lot of space from your storage.
This feature of pacman retaining the packages cache is actually has a good intent in case in the future you want to downgrade a certain package to a lower version. But the cost it it will take up the storage of your manjaro machine.
In this article, you will learn how to clean pacman cache on manjaro so you can remove the unneeded package cache that you don’t want to keep.
Pacman Package Manager Overview
Pacman is a default package manager on Arch Linux and its derivatives distributions including Manjaro.
Written in C programming language and using bsdtar for the packaging format, pacman is a fast and reliable package manager that is easy to use whether to install new packages or update the installed packages.
Pacman relies on software repositories to find and manage packages. Arch Linux has its official repositories, but users can also add third-party repositories to access additional software.
The package dependencies are managed automatically by pacman making the package installation feel seamless and hassle free.
How Cache Works in Pacman
When you use pacman
to install or update packages, it fetches the necessary package files (usually in the form of compressed tarballs with a .pkg.tar.xz
extension) from one of the configured package repositories. These repositories are listed in the /etc/pacman.conf
file.
The downloaded package files are stored in a designated directory on your system, known as the package cache. By default, this directory is located at /var/cache/pacman/pkg/
, but you can configure it to a different location in the /etc/pacman.conf
file if needed.
The saved cache can be used later on when you need to install other packages that require some dependencies that are already available as a cache.
This of course can speed up the package installation process and reduce the use of the internet usage for redownloading the dependencies.
The Pros of Having Cache in Pacman
pacman
maintains a history of downloaded packages in the package cache. This is useful for various reasons, including:
Rollbacks. If you need to downgrade a package, pacman
can do this by retrieving the previous version from the package cache.
Offline Installation. The cache allows you to install or upgrade packages even when you are not connected to the internet, provided you have the required packages in the cache.
Speeding Up Operations. Reinstalling or upgrading packages that are already in the cache can be faster because pacman
doesn’t need to re-download them from the internet.
The Cons of Having Cache in Pacman
Disk Space Usage. The cache directory can occupy a significant amount of disk space, especially if you install or update a large number of packages frequently. This could be a concern on systems with limited storage.
Complexity. For some users, the cache can add complexity to package management. They might need to manage cache cleaning, set up custom cache directories, or configure Pacman to download packages without storing them in the cache.
Potential Conflicts. If you switch between different package management tools or use tools like makepkg
, conflicts can arise when packages are built from cached sources. Manually managing the cache may be necessary to avoid issues.
Clean Pacman Cache on Manjaro
Over time, as you use your Manjaro machine, you may have installed numerous packages to meet your needs, often without realizing that the Pacman cache is steadily accumulating in the background.
At this point, the Pacman cache can consume a significant amount of storage space on your system. To prevent this from affecting your system’s performance and storage availability, it’s important to regularly clean the Pacman cache.
Clean Pacman Cache using Pacman Package Manager
The pacman itself actually gives you the ability to clean the pacman cache which is can be done with just one single command.
To remove all the old versions of installed packages from the cache, you can use the -Sc
option. This will leave the most recent version of each package intact. Open your terminal and run:
sudo pacman -Sc
This will remove the package files that are no longer installed or needed, but it keeps the most recent version of each package in the cache.
To completely clean the entire package cache, including all versions of all packages, you can use the -Scc
option:
sudo pacman -Scc
Be cautious when using this option, as it will remove all packages from the cache. If you later need to reinstall a package, it will have to be re-downloaded.
It’s important to note that while cleaning the cache can free up disk space, it will make it more difficult to roll back to previous versions of packages. Therefore, it’s generally recommended to use -Sc
to remove older package versions while leaving the most recent version.
Clean Pacman Cache Using paccache Utility
Another alternative for cleaning the Pacman cache on Manjaro is to use the paccache utility. Paccache is a specialized tool designed for managing the Pacman cache.
Remove Older Package Versions
One of the primary tasks of paccache
is to remove older versions of packages from your cache. This step is crucial for keeping your system’s disk usage in check. To remove all but the three most recent versions of installed packages, use the following command:
sudo paccache -r
Running this command will clear out older package versions and retain the most recent three for each installed package. This helps you save space while preserving the ability to roll back to a previous version if needed.
Clean Up Uninstalled Package Versions
While the previous step helps manage installed packages, what about packages you’ve uninstalled? To clear out the cache of uninstalled packages and further free up disk space, you can run the following command:
sudo paccache -ruk0
This command removes all versions of packages that are no longer installed on your system. It’s a great way to ensure that your cache doesn’t get cluttered with unnecessary files.
Customize the Number of Versions to Keep
By default, paccache
keeps the three most recent versions of installed packages. However, you can customize this to your liking. For example, if you’d like to keep only the two most recent versions of each package, you can run:
sudo paccache -rk2
This flexibility allows you to balance cache size with your specific needs. Just be mindful of the trade-off between disk space savings and the ability to roll back to older package versions.
In summary, keeping your Arch Linux system tidy and efficient is essential for a smooth computing experience. The paccache
utility makes managing your package cache a breeze, and by following these steps, you can ensure that your system remains lean and mean. Regularly cleaning your package cache not only helps you reclaim disk space but also maintains a more organized and responsive Arch Linux environment.
Conclusion
Pacman is indeed a good package manager that actually pretty fast and reliable to manage your packages in the Arch Linux or Manjaro environment. Despite that, you still need to manage the cache yourself if you wan’t to clean some of the pacman cache.
By following this article, now you should be able to manage and clean pacman cache on Manjaro.