Pacman

From ArchWiki
Revision as of 20:11, 4 May 2009 by Graysky (Talk | contribs) (Related Articles)

Jump to: navigation, search

Template:Pacman i18n Links

Overview

The Pacman package manager is one of the great highlights of Arch Linux. It combines a simple binary package format with an easy-to-use build system (see makepkg and ABS). Pacman makes it possible to easily manage packages, whether they are from the official Arch 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 you to download/install packages with a simple command, complete with all required dependencies.

Pacman is written in the C programming language, so it is fast, light, and very agile. It uses the .tar.gz package format, which further enhances its speed; Gzipped tarballs, though slightly larger, are decompressed much faster than their Bzipped counterparts, and are therefore generally installed more expediently.

Usage

Note: To really learn what pacman can do, read man pacman. The examples below is just a small sample of operations that can be performed.

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

Please read Package Management FAQs for more information about updating and maintaining your system with pacman.

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

See the pacman(8) manpage for more details.

Backing Up and Retrieving a List of Installed Packages for Quick Software Restore

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 are not currently 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.

Configuration

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.

Skip upgrade package

If you for some reason would like to skip upgrading a specific package, you can just add it like this:

IgnorePkg = kernel26

Skip upgrade package group

As with the packages, you can also skip upgrading of a whole package group like this:

IgnoreGroup = gnome

Repositories

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 ftp.archlinux.org as it is throttled.

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

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

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

Template:Box Note


Errors

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.

Further Reading

Man Pages

Related Articles

External Links