The Beginner’s Guide to Using Pacman on Arch Linux

This is a good write up on using Pacman with some options you wouldn’t use that often, so if you’re newer to Arch or Arch based distributions like I am, this is a good overview and reference to build upon. For example, I like to use “sudo pacman -Syyuu” when I update. But of particular interest removing packages with dependencies no longer in use, removing orphaned packages, and clearing the package cache which could be taking up gigabytes of disk space.

https://linuxiac.com/how-to-use-pacman-to-manage-software-on-arch-linux/


By Bobby Borisov

This guide shows how to use Pacman package manager on Arch Linux to manage the software by installing, removing, and updating packages.

Want to install packages on Arch Linux but need to know how? Many people run into this issue when they first move to Arch. But don’t worry; you can easily manage packages on your Arch system using the pacman command. But first, let’s answer an important question.

What Is Pacman Package Manager?

Pacman (stands for Package Manager) is the default package manager for Arch Linux, a lightweight and flexible distro popular among experienced Linux users. Like Arch, Pacman is known for its simplicity, speed, and reliability, combining a simple binary package format with an easy-to-use build system.

Pacman keeps the system up to date by synchronizing package lists with the official Arch repositories. In addition, this client-server model allows the user to download/install packages with a simple command, complete with all required dependencies.

What Will You Learn in This Guide?

We will cover the basics of Pacman, including how to install, update, and remove packages, as well as some more advanced features and tips for using Pacman to its full potential. So, whether you are new to Arch or an experienced Linux user, this guide will help you get the most out of the Pacman.

In addition, this guide also applies to all Arch-based Linux distros, such as Manjaro, EndeavourOS, Garuda Linux, etc., using Pacman as the package manager.

Of course, the official packages are just one of the sources of software on Arch. In addition, you can install some of the thousands available in the AUR repository – Arch’s most significant asset that differentiates it from all other Linux distributions.

However, to do this, different Pacman tools are used, known as AUR helpers. In that case, our comprehensive guide on the subject, “How to Install AUR Packages in Arch Linux,” will greatly help you.

Finally, you can even use one of the excellent GUI Pacman frontends to make installing packages in Arch as easy as possible.

Refresh Package Lists

Because Arch is a rolling-release distro, new packages are added to the distro’s repositories as soon as they are released. As a result, you should keep the Pacman database up to date by updating it fairly frequently.

So, to update the package lists before installing any packages or updating the system, perform the following:

sudo pacman -Sy

Searching for Package

To search for a specific package, for example, vlc, from a sync database (remote server), run:

sudo pacman -Ss vlc

This returns all packages with a matching “vlc” string in the package name or description.

Getting Information About Package

To display the detailed information of the given package from the sync database, for example, nginx, run:

pacman -Si nginx

Installing a New Package with Pacman

Installing a package with Pacman is easy. Just run the following command:

sudo pacman -S vlc

As a result, this process will automatically identify all the necessary dependencies and take care of them. In addition, to install multiple packages with a single command, use a space-separated list of packages.

Installing a Local Package

Pacman stores all downloaded packages in the /var/cache/pacman/pkg directory.

In case you want to install the locally downloaded package, for example, vlc, located in /var/cache/pacman/pkg/ directory, go to the folder where the package is located and enter the following command:

cd /var/cache/pacman/pkg/
sudo pacman -U vlc-3.0.11-2-x86_64.pkg.tar.zst

Update/Upgrade a Package

To update a single package, for example, rsync, run the following:

sudo pacman -S rsync

To update all packages at once on your system, just run the following:

sudo pacman -Syu

However, sometimes you want to upgrade the packages, but you want it to stay at an older version (because you know the newer version has removed a feature or is broken).

So, if the vlc package was causing the problem, you could use the following command for this:

sudo pacman -Syu --ignore=vlc

Remove a Package with Pacman

To remove a package alongside with all its dependencies, run the following command:

sudo pacman -Rs vlc

This command will altogether remove the vlc package and all dependencies. While removing packages, Pacman will keep the critical configuration files with the extension .pacsave.

In addition, if you no longer want them and want to free up the hard drive, you can remove the package along with all its configuration files with the command:

sudo pacman -Rns vlc

Remove Orphaned (Unused) Packages

After removing a package in Arch Linux, there may still be some remaining orphaned (unused) packages that were dependencies of the removed package. However, these orphaned packages are not required anymore, so we can get rid of them to free up some space.

To remove these packages, run:

sudo pacman -Rns $(pacman -Qdtq)

If no orphans were found, the output is:

Searching for Already Installed Packages

Sometimes you want to check for a specific package if it is installed locally. In this case, you can do it using the command below:

pacman -Qs vlc

You can view a list of all the packages installed on your system using the following command:

pacman -Q

Find All Files Owned by a Package

You can find all the files that are installed by a specific package using the following command:

pacman -Ql vlc

This returns the package name and the path to files that it owns.

Find the Package Owner of the File

If you want to check the location of the binary executable file owned by a package, use the -Qo flag.

pacman -Qo /usr/bin/vlc

Download a Package

Sometimes, you can download a package and keep it in your cache without installing it. For example, you can use the downloaded package later. To do so, run:

pacman -Sw vlc

The above command will only download the vlc package and keep it in the cache folder. Pacman stores all downloaded packages in the /var/cache/pacman/pkg directory.

Clean-Up Package Cache

All packages we downloaded during the installation will be stored in the cache directory, i.e., /var/cache/pacman/pkg/. But if you don’t remove them periodically, they will slowly eat up your hard drive space; sooner or later, you could end up with low disk space.

So it is good to remove the cache periodically. For example, to remove all the cached packages and the unused sync database, execute the following:

sudo pacman -Sc

In addition, if you want to remove all files from the cache, use the clean c switch twice. Of course, this is the most aggressive approach and will leave nothing in the cache folder:

sudo pacman -Scc

Conclusion

Arch Linux is one of the most reputed and famous Linux distributions. This guide has covered most of the commands you need to know when using Pacman to install, update, and remove software on Arch.

I hope that it was helpful in your journey with Arch. The official Arch Linux Wiki provides detailed documentation about the Pacman package manager.