-
Notifications
You must be signed in to change notification settings - Fork 0
Clean system files
pacman and yay store different versions of packages and their dependencies in cache folders. Unused files, dependencies, and logs accumulate over time and should periodically be cleared to keep the system's disk space tidy.
By default, pacman stores package files in the /var/cache/pacman/pkg cache. This is a system-wide cache that can be accessed by helpers such as yay.
The paccache utility tool is used to remove old packages from the pacman cache while retaining the 3 most recent versions:
paccache -rIt is not recommended to delete all past versions unless disk space is really needed. Keeping previous versions prevents redundant downloads when downgrading or reinstalling packages.
| Terminal command | Description |
|---|---|
paccache -r |
Clears the /var/cache/pacman/pkg cache of all packages while retaining the last 3 versions. |
paccache -ru |
Clears the pacman cache of uninstalled packages while retaining the last 3 versions. |
paccache -ruk0 |
Clears the pacman cache of all versions of uninstalled packages. |
pacman -Sc |
Clears the pacman cache of all uninstalled packages and unused pacman sync databases. This isn't recommended for network-shared caches. |
Important
It is recommended to clear the pacman and yay caches every 1-2 months.
See: paccache manpage, Pacman wiki: Cleaning the package cache
yay maintains a separate user-specific cache for AUR packages and their build files.
Use this command to clear all cached AUR packages and untracked files:
yay -Scyay will confirm which files of the cache it should remove. By default, it keeps all locally installed packages. yay -Sc is considered an extended pacman command and can also clear the pacman cache at the same time.
Example yay -Sc output below:
Packages to keep:
All locally installed packages
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove all other packages from cache? [Y/n] y
removing old packages from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] y
removing unused sync repositories...
Build directory: /home/kain/.cache/yay
:: Do you want to remove all other AUR packages from cache? [Y/n] y
removing AUR packages from cache...
:: Do you want to remove ALL untracked AUR files? [Y/n] y
removing untracked AUR files from cache...Note
See: yay command library
systemd logs system activity in the journal and is used to troubleshoot issues. Open the journal by entering journalctl in a terminal.
To maintain a log of the past 6 weeks while clearing excess logs, run:
journalctl --vacuum-time=6weeksIt is recommended to keep a minimum of 4 weeks of logs, but the amount can be adjusted to personal preference. By default, the journal can only contain up to 4 GB of information.
Note
See: systemd journal
Orphans are dependencies that are no longer needed by any program. These accumulate on the system when:
-
Packages are uninstalled with
pacman -R <package-name>instead of the more thorough-Rsoption. -
A new package version no longer requires a dependency it originally used or was installed with.
This combined command will list orphans (unused package dependencies). After user confirmation, and recursively removes them along with their configuration files:
sudo pacman -Qdtq | sudo pacman -Rns -After running sudo pacman -Qdtq | sudo pacman -Rns -, enter Y to confirm removal of the listed orphans.

Tip
If the terminal outputs error: argument '-' specified with empty stdin, this means there are no orphans to remove.
If there are orphan dependencies that you wish to keep, specify beforehand which ones should be excluded from removal with this command:
sudo pacman -D --asexplicit <pkg>| Command | Description |
|---|---|
sudo pacman -Qdtq |
Lists all orphan dependencies. This is useful for checking if there are orphans that should be kept. |
sudo pacman -Rns <pkg> |
Removes a specified orphan. |
sudo pacman -D --asexplicit <pkg> |
Excludes the specified orphan from removal. |
Note