The Ultimate Guide to Pacman Commands on Arch Linux

Package managers are the backbone of a Linux system. It is only thanks to them that you can install and enjoy the latest software on your desktop. Pacman, a portmanteau of the words “package” and “manager”, is the default package manager on Arch-based systems.

Although Pacman is fairly easy to learn compared to its counterparts, users from other distribution families find it frustrating to adapt to Pacman’s short one-character arguments. So let’s take a look at Pacman, its various options, and how you can use it to manage packages on Arch Linux like a pro.

Pacman Commands Guide

Like other Linux commands, Pacman follows a basic command syntax with predefined flags and arguments:

sudo pacman -options pkgname

…or -options are the flags you use to invoke different functions and package name is the name of the package(s) you want to operate on.

Upgrade packages using Pacman

When you install Linux, the first thing to do is to update the installed packages. The following Pacman command will sync installed packages with repositories and upgrade them if updates are available:

sudo pacman -Syu

To upgrade only a particular package, specify the package name as an argument with the -S flag:

sudo pacman -S pkgname

Conversely, you can also prevent a package from being upgraded in Arch Linux. This will ask you to change the pacman.conf file located in /etc directory, however.


Installing a new package

To add new programs to your system, you will need to install packages from the official Arch repositories. the -S flag helps you by providing an easy way to download and install packages. The basic command syntax is:

sudo pacman -S pkgname

For example, to install the root package:

sudo pacman -S root


install packages with pacman

Specify a space-separated list of packages to install multiple packages with a single command:

sudo pacman -S pkgname1 pkgname2 pkgname3

Like Ubuntu, Arch Linux also has several repositories from which you can get your packages. If a package with the same name is available on multiple repositories, choose the one you want by specifying the repository name.

sudo pacman -S repo/pkgname

To install a package from the “community” repository:

sudo pacman -S community/pkgname

For those who wish to keep a backup of certain packages for later use, you can download a package without installing it using the -Sw flag:

sudo pacman -Sw pkgname

You can also download and install a package directly using the package source URL. To do this, use the -U flag and indicate the link to the archive:

sudo pacman -U

Installing a local package using an archive

Sometimes when you can’t find a package in the Arch repositories, you can download its tarball/archive from the internet and install it manually using Pacman. the -U flag allows you to locally install a package using a downloaded archive:

sudo pacman -U /path/to/archive/pkgname.pkg.tar.zst

Usually, Pacman keeps track of installed packages using the pacman -S package_name order and regularly check whether an update is available for them or not. But if you’re installing a package using a downloaded tarball, you’ll need to manually check for package updates.

Therefore, it is recommended to download the packages from the official repositories. Only if the package is not available in the official repositories you should download and install a package locally using its archive.

If you want to downgrade a package by installing it from the package cache, use the following command format:

sudo pacman -U file://path/to/archive/pkgname.pkg.tar.zst

Find a package to install

Pacman lets you search for packages in the local database, sync database, and file database using -Q, -Sand -F flags, respectively.

When you do not know the exact name of a package, you can search for it in the synchronization database using the -Ss flag.

sudo pacman -Ss query

For example:

search for packages on arch linux

To search for a package already installed on your system, use the -Qs flag:

sudo pacman -Qs query

If you want to know more about a package before installing it, use the -Yes flag with the command:

sudo pacman -Si pkgname

To list orphaned packages, i.e. installed dependencies that are not required by any package on the system:

sudo pacman -Qdt

You can combine the above command with the pacman-Rns to free up space on your system as follows:

sudo pacman -Rns $(pacman -Qdt)

Uninstall a package

When you want to remove a package installed using Pacman, use the -R option.

sudo pacman -R pkgname


uninstall packages with pacman

The above command will only remove the specified package and keep its dependencies intact. To remove dependencies with the package, add the -s flag to command:

sudo pacman -Rs pkgname

If the package you want to remove acts as a dependency of another package, you can remove both packages using the additional command -vs flag:

sudo pacman -Rsc pkgname

Usually, Pacman keeps configuration files associated with a package and creates a backup of these files when you remove the package. To override this default behavior and remove packages without backing up configuration files, use the command -not flag with the remove command:

sudo pacman -Rns pkgname

Free up space by cleaning the package cache

When you install a package using Pacman, it does not remove downloaded files. Instead, it stores them in the package cache until deleted by the user. This can lead to insufficient storage issues as these cache files can accumulate and take up a lot of your system storage.

To solve this problem, it is important to clean the package cache regularly.

paccache -r

You can choose to keep only the cache files of currently installed packages and remove the rest using the following command:

pacman -Sc

Pacman vs. APT vs. DNF: A Comparison

Compared to other package managers such as APT or DNF, Pacman can be complicated for new users given the complex and unintuitive flags used in the commands. But that’s also the beauty of Pacman; you can get things done quickly without typing multiple lines of commands in the terminal.

Let’s compare commands for updating and upgrading packages using APT and Pacman. If you are using a Debian-based distro, you will need to run two commands to achieve this goal:

sudo apt update
sudo apt upgrade

You can also concatenate the two commands above using the && operator, but it still falls short of its Pacman counterpart:

sudo pacman -Syu

Overall, the APT and DNF commands are self-explanatory and easy to understand for Linux newcomers, while the Pacman commands are concise and get more done with just a few keystrokes.

Intensify! Explore the Arch User Repository

As you may know, Pacman can only get packages from official Arch repositories. But a large portion of the packages reside on the community-maintained Arch User Repository (AUR). To install packages from the AUR you need an AUR helper like yay.

The AUR is a repository created and maintained by users, for users. Anyone can add their packages to the AUR in the form of PKGBUILDs provided they have sufficient knowledge of the AUR in the first place.

what is the aur

What is the Arch User Repository (AUR)? All you need to know

Read more

About the Author

Calvin W. Soper