Skip to the content
pacman-master.com

pacman -Sc: clearing the package cache

To clear the package cache, run sudo pacman -Sc. It deletes the cached files of packages that are no longer installed, and the sync databases of repositories that are no longer configured. What the local database records is the version a package is installed at, so the file kept for a package still on the machine is that one version and older files for it go with the rest.

sudo pacman -Sc
-S
--sync — install packages from the repositories and upgrade the system
-c
--clean — remove the cached files of packages that are no longer installed, and the sync databases of repositories that are no longer configured

Needs root.

What it does. Delete the cached files of packages that are no longer installed, and the sync databases of repositories that are no longer configured.

Watch out. The cache is what lets you reinstall or step back to a previous version without a network; deleting it is not free.

Step by step

  1. See how much is actually there

    The cache is a plain directory, so the size can be read before anything is deleted. du is part of coreutils, not of pacman.

    not pacmandu -sh /var/cache/pacman/pkg
  2. Delete what is no longer installed

    This is the safe half: what stays is the installed version of a package still on the machine, so reinstalling it offline still works, while older files for it go. The same run also drops the sync databases of repositories that are no longer configured, which cost nothing to fetch again.

    cautionsudo pacman -Sc
  3. Empty it completely, only if you accept the cost

    The doubled c removes every file, including those for installed packages. After this a reinstall or a step back to an older version has to download again.

    cautionsudo pacman -Scc

What the cache is

The package cache is the directory pacman keeps downloaded package files in, at /var/cache/pacman/pkg, so that the same file does not have to be fetched twice.

Nothing in it is needed for the system to run. It is needed for two things that only matter at the moment you need them: reinstalling a package without a network, and installing an older version again because a new one misbehaves. The files in the cache are the only copy of those older versions you have.

-Sc and -Scc

Against a worked cache holding 6 files for three packages, two of which are still installed:

What each cleaning command leaves in the package cacheA worked cache holding six package files down the left, with the two that are the installed versions marked as in use. Three columns to the right show the same six files after pacman -Sc, after pacman -Scc and after paccache -rk2, each file marked kept or deleted, with the two totals under each column./var/cache/pacman/pkgfirefox-141.0-1firefox-142.0-1firefox-143.0-1in usevim-9.1.1-1vim-9.1.2-1in useoldpkg-2.0-16files in the cachepacman -Scdeleteddeletedkeptdeletedkeptdeleted2kept4deletedpacman -Sccdeleteddeleteddeleteddeleteddeleteddeleted0kept6deletedpaccache -rk2deletedkeptkeptkeptkeptkept5kept1deleted
-Sc goes by whether the cached file is the version that is installed, and takes the sync databases of repositories that are no longer configured with it. paccache goes by how many versions you want to keep, so -rk2 leaves more of an installed package behind than -Sc does.
CommandDeletesKeepsDanger
sudo pacman -ScThe cached files of packages that are no longer installed, and the sync databases of repositories that are no longer configuredThe file for the version each package is installed atcaution
sudo pacman -SccEvery file in the cacheNothingcaution

-Scc also removes the file for the version you are running right now. If a package turns out to be broken after an upgrade, the copy you would have reinstalled is the one this command deleted.

CleanMethod in /etc/pacman.conf decides which cached file counts as installed. Its default, KeepInstalled, goes by the local database, which records the version that is installed. KeepCurrent goes by the sync databases instead, so the file that survives is the one the repositories offer at that moment.

Keeping the last few versions instead

Neither command takes a number of versions to keep, and -Sc is not the gentle one of the pair for a package you still have: it leaves one file for that package, the installed version. A program outside pacman takes the number: the pacman-contrib package ships paccache, whose -k says how many recent versions of a package stay, so paccache -rk2 leaves two of them where -Sc leaves one. The paccache page puts the three side by side on the same worked cache. It is a separate program with its own options, so check its own help before running it:

not pacmanpaccache --help

Not part of pacman; it comes from the pacman-contrib package.

Common questions

How do I clear the pacman cache?

Run sudo pacman -Sc. It deletes the cached files of packages that are no longer installed, and the sync databases of repositories that are no longer configured. The local database records the version a package is installed at, so for a package still on the machine that one file stays and older files for it go.

What is the difference between -Sc and -Scc?

-Sc deletes the cached files of packages that are no longer installed, and the sync databases of repositories that are no longer configured. -Scc deletes every file in the cache, including the ones for packages you are currently running.

Where is the pacman cache?

At /var/cache/pacman/pkg. It is an ordinary directory of package files, so its size can be measured with du before you decide to clear it.

How to check this page

Two commands on your own machine: pacman -<operation> --help lists the modifiers that operation accepts, and man pacman opens the pacman(8) manual page these descriptions are written from. Where the descriptions come from, and what this site is not, is set out on the about page.

This page was last edited on .