Pacman Usage

Posted: March 24, 2009 in archlinux

Installing Packages

Before installing and upgrading packages, it is a good idea to synchronize the local package database with the remote repositories.

pacman -Sy

…or, equivalently:

pacman –sync –refresh

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

pacman -S package_name1 package_name2

Sometimes there are multiple versions of a package in different repositories (e.g. extra and testing). You can specify which one to install:

pacman -S extra/package_name
pacman -S testing/package_name

You can also refresh the package database before installing a package in one command:

pacman -Sy package_name

Removing Packages

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

pacman -R package_name

To remove a package’s dependencies which aren’t required by any other installed package:

pacman -Rs package_name

By default, pacman backs up configuration files of removed applications in place by adding the extension *.pacsave to them. If you want to delete configuration files as well when removing the corresponding package (this behavior is called purging on Debian-based systems) you can use:

pacman -Rn package_name

Of course, this can be extended with -s to also delete now-unnecessary dependencies. Thus, the command to truly remove a package, its configuration, and all dependencies which aren’t needed anymore is:

pacman -Rsn package_name

Note! Pacman will not remove configuration files that are created after the package was installed. You can manually remove them from your home folder.

Upgrading the System

Pacman can update all packages on the system with just one command. This could take quite a while depending on how up-to-date your system is.

pacman -Su

However, the best option is to synchronize the repository databases AND update your system in one go with the following:

pacman -Syu

Querying the Package Database

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

pacman -Ss package

To search for already installed packages:

pacman -Qs package

Once you know the name of the package you are looking for, you can get more information about it:

pacman -Si package
pacman -Qi package

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

pacman -Ql package

You can also query the database to know which package a file on your file system belongs to.

pacman -Qo /path/to/a/file

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

pacman -Qdt

Pacman queries the local package database with the -Q flag. See:

pacman -Q –help

…and queries the sync databases with the -S flag. See:

pacman -S –help

It is good practice to keep periodic backups of all pacman-installed packages. In the event of a system crash which is unrecoverable by other means, pacman can then easily reinstall the very same packages onto a new installation.

First, backup the current list of packages (which are available in a repository):

pacman -Qqe | grep -v “$(pacman -Qmq)” > pkglist

Store the pkglist on a USB key or other convenient medium.

Copy the pkglist file to the new installation, and navigate to the directory containing it.

Issue the following command:

pacman -S $(cat pkglist)

Additional Information

Pacman is quite an extensive package management tool. Here is just a brief collection of other features.

* Download a package without installing it:

pacman -Sw package_name

* Install a ‘local’ package (not from a repository):

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

* Install a ‘remote’ package (not from a repository):

pacman -U http://www.examplepackage/repo/examplepkg.tar.gz

* Clean the package cache of packages that’s currently not installed (/var/cache/pacman/pkg):

pacman -Sc

* Completely cleans the package cache

pacman -Scc

Warning: About pacman -Scc, you should do this only if you are sure you will not need to downgrade any package. pacman -Scc removes all packages from the cache.

* For removing orphans (recursively; be careful!):

pacman -Rs $(pacman -Qtdq)

* For reinstalling all packages on your system (which are available in a repository):

pacman -S $(pacman -Qq | grep -v “$(pacman -Qmq)”)

* To get a sorted list of local packages and their size:

LANG=C pacman -Qi | sed -n ‘/^Name[^:]*: \(.*\)/{s//\1 /;x};/^Installed[^:]*: \(.*\)/{s//\1/;H;x;s/\n//;p}’ | sort -nk2

For a more detailed list of switches please refer to pacman –help or man pacman.


Pacman configuration is located in /etc/pacman.conf. In depth information about the configuration file can be found in man pacman.conf.
General Options

General options are in [options] section. Read the man page or look in the default pacman.conf for information on what can be done here.

In this section you define which repositories to use, as referred to in /etc/pacman.conf. They can be defined directly here, or you can include them from another file.

All official repositories use the same /etc/pacman.d/mirrorlist file which contains a variable ‘$repo’, so you only need to maintain one list.

The following is an example for the official repositories which have a lot of mirrors. Avoid using as it is throttled.

# Add your preferred servers here, they will be used first
Include = /etc/pacman.d/mirrorlist

# Add your preferred servers here, they will be used first
Include = /etc/pacman.d/mirrorlist

# Add your preferred servers here, they will be used first
Include = /etc/pacman.d/mirrorlist

Note: Care should be taken when using testing repository!


If you receive the following error:

not found in sync db

…this likely due to the package not being located because the repository has not been set correctly.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s