Reclaim Storage Space on Arch Linux with Pacman and Paccache

Updated on May 24, 2021
Reclaim Storage Space on Arch Linux with Pacman and Paccache header image

Introduction

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.

Update your System

It's a best practice to update your Vultr Arch Linux server before following this guide.

Orphaned Packages

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.

Checking for 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.

Removing 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.

Removing All Orphans

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

Cleaning the Package Cache

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.

Install paccache

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

Remove Older Cached Packages

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.

Removing Cached Uninstalled Packages

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

More Information