Arch Linux uses the pacman package manager, which stores earlier versions of installed packages in its cache. Pacman also occasionally leaves unneeded dependencies on the system. Cleaning these old packages can free up storage space on your Arch Linux system.
It's a best practice to update your Vultr Arch Linux server before following this guide.
Many packages on Arch Linux systems have dependencies. When you uninstall a package, old dependencies may remain on the system, wasting storage space. These unneeded dependencies are called orphans.
Use pacman to list all orphans on your server.
# sudo pacman -Qdtq
Each line of output is the name of an orphan package. If there is no output, your system has no orphans.
You can uninstall orphans, like any other package, with pacman.
# sudo pacman -Rsn [name]
[name] is an orphaned package provided by the previous command.
If there are many orphans, you can remove all of them with the following command:
# sudo pacman -Qtdq | pacman -Rns -
If there are no orphans on the system, you'll see the following message, which you can ignore.
error: argument '-' specified with empty stdin
When you install a package, pacman saves a copy of the package in the package cache. This allows you to roll a package back to a earlier version if there is an issue. However, pacman does not remove old versions in the cache, and the old versions take up extra space.
You can manage the package cache with
paccache. This tool is not installed by default, so you must install it yourself with the following command.
# sudo pacman -Syu pacman-contrib
Although having a cache of earlier package versions is helpful, keeping only the two most recent versions of each package is enough. The following command deletes all cached versions of packages other than the two most recent versions.
# sudo paccache -rk2
If you would rather keep a different number of prior versions cached, change the number in the command above.
Uninstalling a package does not remove it from the cache. There is usually no reason to keep the cached packages, and you can purge them with the following command.
# sudo paccache -ruk0