Pacman Package Manager for Arch-Based Distributions

The pacman is a package manager for arch-based distributions such as Manjaro, EndeavourOS, ArcoLinux, etc. If you have tried Ubuntu or Debian, you may already know that the apt package manager is the default for all Debian-based distributions.

The role of the package manager is to provide users with an option to manage package installation, updates, removal, etc. pacman is also one of the package managers for arch-based distributions, providing you with the combination of binary package format with an easy-to-use build system.

Pacman aims to make it easier for you to manage packages from official repositories or your builds. It will also keep your system up-to-date by synchronizing the package list from the master server.

In this beginner’s guide, I’ll explain how to use the pacman package manager for arch-based distributions.

Update Database with Pacman

To have the latest version information of packages, synchronize your pacman database with the master server using the below command.

$ sudo pacman -Sy

Note: Avoid refreshing the package list without upgrading the system while installing packages from pacman. For example, if any xyz_package package is not available, do not run pacman -Sy xyz_package instead of pacman -Syu xyz_package, as this could lead to dependency issues.

Upgrade Packages with Pacman

Issue the below command to upgrade the packages to their latest versions available in the pacman database.

$ sudo pacman -Syu

Whereas

  • S stands for sync
  • y is for refresh (local cache)
  • u is for system upgrade

Issue the below command to combine the pacman database sync from the master server with the upgrade command.

$ sudo pacman -Syyu

Search Package with Pacman

Pacman can search for packages from the pacman database using the -Ss option, as shown below.

$ pacman -Ss package

When you issue the above command, it will print the output without colour, creating confusion while differentiating packages. Pacman knows the colour scheme for the output, but the function is disabled. In that case, either use the built-in pacsearch command with package-name as pacsearch package-name or enable the colour output for pacman by editing the /etc/pacman.conf configuration file with your choice of text editor.

$ sudo nano -c /etc/pacman.conf     

After the pacman configuration file is open, uncomment the color keyword from line number 36, as shown below.

Enabling color ouput for pacman command
Enabling colour output for pacman command

After editing the file, save, close, and re-execute the pacman -Ss package to get the colour output.

To search for already installed packages.

$ pacman -Qs package

To search for package file names in remote packages.

$ pacman -F package

Issue the below command to view the dependency tree of a package.

$ pactree package

Package Information with Pacman

Issue the following command to list the available installed packages on your system:

$ pacman -Q

The list might contain a lot of packages, so filter out the specific one using the grep command, as shown below.

$ pacman -Q | grep package

After filtering the package, if you want more information about the package, such as Name, Version, Description, Architecture, URL, Installed Size, etc., as shown below.

$ pacman -Qi package

By default, the -Qi option will list all the information related to the specified package. If you are interested in knowing the specific information, such as the “Installed Size“, pipe grep command with pacman.

$ pacman -Qi package | grep -e "Installed Size"

Issue the following command to list all the package names with their “Installed Size“.

$ pacman -Qi | grep -e "Name" -e "Installed Size" 

Install Packages with Pacman

To install single or multiple packages, including dependencies, execute the below command.

$ sudo pacman -S package_1 package_2

Suppose you have multiple package versions in different repositories (ex: extra and testing). To install the other version of a package located in extra, specify the repository name with the package name, as shown below.

$ sudo pacman -S extra/package

Packages sharing similar patterns in their names can be installed using the curly brace instead of repeating them repeatedly, as shown below.

$ sudo pacman -S python-{pip,pytest,tkinter}

Do not provide space between the commas to avoid an error.

Download Packages with Pacman

You can easily download a package without installing it by using the -Sw option with the package name, as shown below.

$ sudo pacman -Sw package

The downloaded file will be stored in the /var/cache/pacman/pkg/ directory with the package name compressed in .tar.xz.zst format. If you want to install the local package, not from the remote repository, use the -U option shown below.

$ sudo pacman -U /var/cache/pacman/pkg/package.tar.xz.zst

You can pipe the grep command with the package name to find any other package that has been downloaded using the pacman command.

$ ls /var/cache/pacman/pkg | grep "package"

To install a remote package, not from the official repository.

$ pacman -U http://www.example.com/repo/package.pkg.tar.zst

Removing Packages with Pacman

When you don’t need the installed packages anymore, you can easily remove them from your system. To remove a package from your system, use the -R option with the package name, as shown below.

$ sudo pacman -R package

Issue the following command to remove a package with its dependencies from your system.

$ sudo pacman -Rs package

Issue the following command if you forget to remove dependencies of recently removed packages. For example, the package that needed the dependencies was already being removed, so in that case, dependencies are no longer required.

$ pacman -Qdtq | pacman -Rs -

Cleaning the Package Cache

At the time of installation, pacman downloads the compressed file of the package and stores it in the /var/cache/pacman/pkg/ directory. This compressed file remains undeleted even after the installation is complete.

The advantage of having them is that they allow you to easily downgrade or reinstall a package after removal directly from the cache folder instead of downloading it.

After a certain time, it might grow in size, requiring removal. This can be done using the paccache(8) script, provided within the pacman-contrib package. It will remove installed and uninstalled packages, leaving the last three packages, as shown below.

$ paccache -r

Issue the following command to remove the cached packages currently not installed and the unused sync database, as shown below.

$ pacman -Sc

Issue the following command to remove everything from the cache directory without leaving anything.

$ pacman -Scc

Troubleshooting

Below are some of the command problems you might face as a beginner.

Failed to commit transaction (conflicting files)

If you see the following error.

error: could not prepare transaction
error: failed to commit transaction (conflicting files)
package: /path/to/file exists in filesystem
Errors occurred, no packages were upgraded.

This is happening because pacman has detected a file conflict and will not overwrite files for you.

To resolve this problem, the first step is to find another package that owns the file using the pacman -Qo /path/to/file command. If the file is owned by another package, file a bug report. If not, then rename the file that “exists in the filesystem” and re-issue the update command. If all goes well, the file may then be removed.

Instead of manually renaming and later removing all the files that belong to the package in question, you may explicitly run pacman -S --overwrite glob package to force pacman to overwrite files that match glob.

Failed to commit transaction (invalid or corrupted package)

Look for .part files (partially downloaded packages) in /var/cache/pacman/pkg/ and remove them (often caused by the usage of a custom XferCommand in pacman.conf).

$ find /var/cache/pacman/pkg/ -iname "*.part" -delete

Failed to init transaction (unable to lock database)

When pacman is about to alter the package database, for example, by installing a package, it creates a lock file at /var/lib/pacman/db.lck. This prevents another instance of pacman from trying to alter the package database at the same time.

If pacman is interrupted while changing the database, this stale lock file can remain. If you are certain that no instances of pacman are running, then delete the lock file.

First, verify if there is any process still using the lock file.

$ fuser /var/lib/pacman/db.lck

If the above command didn’t output anything, you can remove the lock file using the following command.

$ rm /var/lib/pacman/db.lck

Cheatsheet

Below is the summary of all commands.

CommandDescription
sudo pacman -SyUpdate pacman database
sudo pacman -SyuUpgrade All Packages
sudo pacman -SyyuUpdate and Upgrade All Packages
pacman -Ss packageSearch for packages from the local database
pacman -Qs packageSearch for already installed packages
pacman -F packageSearch for package file names in remote packages
pactree packageView the dependency tree of a package.
pacman -QAll installed packages
pacman -Qi packageDetail package information
sudo pacman -S package_1 package_2Install packages
sudo pacman -S extra/packageInstall different versions of package from a different repository
sudo pacman -S python-{pip,pytest,tkinter}Install all packages sharing similar patterns in their names
sudo pacman -Sw packageDownload the compressed file of the package
sudo pacman -U /var/cache/pacman/pkg/package.tar.xz.zstInstall downloaded package
pacman -U http://www.example.com/repo/package.pkg.tar.zstInstall package from a remote location
sudo pacman -R packageRemoving packages without dependencies
sudo pacman -Rs packageRemoving packages with dependencies
pacman -Qdtq | pacman -Rs -Remove unused dependencies
paccache -rRemove cache leaving the recent three packages
pacman -SccRemove everything from the cache directory

I tried to cover all the commands that one needs. If there is anything I missed or you want to give a suggestion, then feel free to comment down below.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments