Pacman Package Manager

From Onix OS

The pacman package manager is one of the major distinguishing features of Arch Linux. It combines a simple binary package format with an easy-to-use build system. The goal of pacman is to make it possible to easily manage packages, whether they are from the official repositories or the user's own builds.

Pacman keeps the system up to date by synchronizing package lists with the master server. This server/client model also allows the user to download/install packages with a simple command, complete with all required dependencies.

Pacman is written in the C programming language and uses the tar format for packaging.


What follows is just a small sample of the operations that pacman can perform.

Installing packages

A package is an archive containing:

  • all of the (compiled) files of an application
  • metadata about the application, such as application name, version, dependencies, ...
  • installation files and directives for pacman
  • (optionally) extra files to make your life easier, such as a start/stop script

Arch's package manager pacman can install, update, and remove those packages. Using packages instead of compiling and installing programs yourself has various benefits:

  • easily updatable: pacman will update existing packages as soon as updates are available
  • dependency checks: pacman handles dependencies for you, you only need to specify the program and pacman installs it together with every other program it needs
  • clean removal: pacman has a list of every file in a package; this way, no files are unintentionally left behind when you decide to remove a package.

Installing specific packages

To install a single package or list of packages, including dependencies, issue the following command:

# pacman -S package_name1 package_name2 ...

To install a list of packages with regex (see this forum thread):

# pacman -S $(pacman -Ssq package_regex)

Sometimes there are multiple versions of a package in different repositories (e.g. extra and testing). To install the version from the extra repository in this example, the repository needs to be defined in front of the package name:

# pacman -S extra/package_name

To install a number of packages sharing similar patterns in their names one can use curly brace expansion. For example:

# pacman -S plasma-{desktop,mediacenter,nm}

This can be expanded to however many levels needed:

# pacman -S plasma-{workspace{,-wallpapers},pa}
Virtual packages

A virtual package is a special package which does not exist by itself, but is provided by one or more other packages. Virtual packages allow other packages to not name a specific package as a dependency, in case there are several candidates. Virtual packages cannot be installed by their name, instead they become installed in your system when you have install a package providing the virtual package.

Installing package groups

Some packages belong to a group of packages that can all be installed simultaneously. For example, issuing the command:

# pacman -S gnome

will prompt you to select the packages from the group that you wish to install.

Sometimes a package group will contain a large amount of packages, and there may be only a few that you do or do not want to install. Instead of having to enter all the numbers except the ones you do not want, it is sometimes more convenient to select or exclude packages or ranges of packages with the following syntax:

Enter a selection (default=all): 1-10 15

which will select packages 1 through 10 and 15 for installation, or:

Enter a selection (default=all): ^5-8 ^2

which will select all packages except 5 through 8 and 2 for installation.

To see what packages belong to the gnome group, run:

# pacman -Sg gnome

Also visit to see what package groups are available.

Removing packages

To remove a single package, leaving all of its dependencies installed:

# pacman -R package_name

To remove a package and its dependencies which are not required by any other installed package:

# pacman -Rs package_name

The above may sometimes refuse to run when removing a group which contains otherwise needed packages. In this case try:

# pacman -Rsu package_name

To remove a package, its dependencies and all the packages that depend on the target package:

# pacman -Rsc package_name

To remove a package, which is required by another package, without removing the dependent package:

# pacman -Rdd package_name

Pacman saves important configuration files when removing certain applications and names them with the extension: .pacsave. To prevent the creation of these backup files use the option:

# pacman -Rn package_name

Upgrading packages

Pacman can update all packages on the system with just one command. This could take quite a while depending on how up-to-date the system is. The following command synchronizes the repository databases and updates the system's packages, excluding "local" packages that are not in the configured repositories:

# pacman -Syu

Querying package databases

Pacman queries the local package database with the flag, the sync database with the flag and the files database with the flag.

Pacman can search for packages in the database, searching both in packages' names and descriptions:

$ pacman -Ss string1 string2 ...

Sometimes, builtin ERE (Extended Regular Expressions) can cause a lot of unwanted results, so it has to be limited to match the package name only; not the description nor any other field:

$ pacman -Ss '^vim-'

To search for already installed packages:

$ pacman -Qs string1 string2 ...

To search for package file names in remote packages:

$ pacman -F string1 string2 ...

To display extensive information about a given package:

$ pacman -Si package_name

For locally installed packages:

$ pacman -Qi package_name

Passing two flags will also display the list of backup files and their modification states:

$ pacman -Qii package_name

To retrieve a list of the files installed by a package:

$ pacman -Ql package_name

To retrieve a list of the files installed by a remote package:

$ pacman -Fl package_name

To verify the presence of the files installed by a package:

$ pacman -Qk package_name

Passing the flag twice will perform a more thorough check.

To query the database to know which package a file in the file system belongs to:

$ pacman -Qo /path/to/file_name

To query the database to know which remote package a file belongs to:

$ pacman -F /path/to/file_name

To list all packages no longer required as dependencies (orphans):

$ pacman -Qdt

To list all packages explicitly installed and not required as dependencies:

$ pacman -Qet

See Pacman/Tips and tricks for more examples.

Cleaning the package cache

Pacman stores its downloaded packages in does not remove the old or uninstalled versions automatically. This has some advantages:

  1. It allows to downgrade a package without the need to retrieve the previous version through other means, such as the Arch Linux Archive.
  2. A package that has been uninstalled can easily be reinstalled directly from the cache folder, not requiring a new download from the repository.

However, it is necessary to deliberately clean up the cache periodically to prevent the folder to grow indefinitely in size.

The man script, provided within the package, deletes all cached versions of installed and uninstalled packages, except for the most recent 3, by default:

# paccache -r

You can also define how many recent versions you want to keep. To retain only one past version use:

# paccache -rk1

Add the switch to limit the action of paccache to uninstalled packages. For example to remove all cached versions of uninstalled packages, use the following:

# paccache -ruk0

Pacman also has some built-in options to clean the cache and the leftover database files from repositories which are no longer listed in the configuration file Template:Ic. However pacman does not offer the possibility to keep a number of past versions and is therefore more aggressive than paccache default options.

To remove all the cached packages that are not currently installed, and the unused sync database, execute:

# pacman -Sc

To remove all files from the cache, use the clean switch twice, this is the most aggressive approach and will leave nothing in the cache folder:

# pacman -Scc

Additional commands

Download a package without installing it:

# pacman -Sw package_name

Install a 'local' package that is not from a remote repository (e.g. the package is from the AUR):

# pacman -U /path/to/package/package_name-version.pkg.tar.zst

To keep a copy of the local package in pacman's cache, use:

# pacman -U file:///path/to/package/package_name-version.pkg.tar.zst

Install a 'remote' package (not from a repository stated in pacman's configuration files):

# pacman -U

Pacman always lists packages to be installed or removed and asks for permission before it takes action.

Installation reason

The pacman database distinguishes the installed packages in two groups according to the reason why they were installed:

  • explicitly-installed: the packages that were literally passed to a generic pacman Template:Ic or Template:Ic command;
  • dependencies: the packages that, despite never (in general) having been passed to a pacman installation command, were implicitly installed because required by another package that was explicitly installed.

When installing a package, it is possible to force its installation reason to dependency with:

# pacman -S --asdeps package_name

When reinstalling a package, though, the current installation reason is preserved by default.

To change the installation reason of an already installed package, execute:

# pacman -D --asdeps package_name

Search for a package that contains a specific file

Sync the files database:

# pacman -Fy

For advanced functionality install pkgfile, which uses a separate database with all files and their associated packages.

More Details on Arch Linux Wiki.