pacman
From ArchWiki
Article summary |
---|
An overview of Arch Linux's package manager. |
Available in languages |
Česky |
Dansk |
Deutsch |
English |
Español |
Français |
Italiano |
Nederlands |
Polski |
Português de Portugal |
Romanian |
Русский |
简体中文 |
한국어 |
Türkçe |
Ελληνικά |
日本語 |
Related articles |
Arch Build System |
Arch User Repository |
Downgrading Packages |
Improve Pacman Performance |
Mirrors |
pacman GUI Frontends |
pacman Rosetta |
pacman Tips |
Manual pages |
libalpm(3) |
makepkg(8) |
makepkg.conf(5) |
pacman(8) |
pacman.conf(5) |
PKGBUILD(5) |
repo-add(8) |
The pacman package manager is one of the main features of Arch Linux. It combines a simple binary package format with an easy-to-use build system (see makepkg and Arch Build System). The goal of pacman is to make 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. It uses the .tar.gz package format, in an effort to further enhance its speed; Gzipped tarballs, though slightly larger, are decompressed much faster than their Bzipped counterparts, and are therefore generally installed more expediently.
Configuration
pacman configuration is located in /etc/pacman.conf. This is the place where the user configures the program to work in the desired manner. In depth information about the configuration file can be found in man pacman.conf.
General options
General options are in the [options] section. Read the man page or look in the default pacman.conf for information on what can be done here.
Skip package from being upgraded
To skip upgrading a specific package, add it to the pertinent section:
IgnorePkg=kernel26
Skip package group from being upgraded
As with packages, skipping a whole package group is also possible:
IgnoreGroup=gnome
Repositories
This section defines which repositories to use, as referred to in pacman.conf. They can be stated here directly, or included from another file.
All official repositories use the same /etc/pacman.d/mirrorlist file which contains a variable, '$repo', making it a requisite to maintain only one list.
The following is an example for the official repositories which have numerous 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
Usage
To read other examples of what pacman can do, refer to man pacman. The examples below are just a small sample of operations that can be performed.
Installing packages
To install 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). Specify which one to install:
# pacman -S extra/package_name # pacman -S testing/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 are not required by any other installed package:
# pacman -Rs package_name
pacman saves important configuration files when removing certain applications and names them with the extension: .pacsave. To delete these backup files use the -n option:
# pacman -Rn package_name # pacman -Rns 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 best option is to synchronize the repository databases and update the system in one go, with the following:
# pacman -Syu
pacman is a powerful package management tool, but it does not attempt to "do everything", as it were. Read The Arch Way if this confuses you. Rather, users must be vigilant and take responsibility for maintaining their own system. When performing a system update (pacman -Syu), for example, it is essential that users read all information output by pacman and use common sense.
For example, if kernel26 is to be updated to a new minor version, the cautious user immediately recognizes that packages that include kernel modules (such as catalyst and virtualbox-modules) must be updated/rebuilt as well. If a kernel26 update is available, but no updates are yet available for catalyst, it is not recommended to update kernel26 unless willing to deal with catalyst breaking!
This is not a problem unique to Arch Linux, per se; kernel modules must be built against the running kernel. However, fixed-release distributions usually ensure that kernel updates are accompanied with updates to all "affected" packages. As a cutting-edge rolling-release distribution, kernel updates are available immediately in Arch Linux. "Affected" packages are usually updated within a matter of hours of a kernel update, but may not be available until your repositories are synced. Always use common sense!
Another example: during an update, pacman indicates that a new version of xorg-server is available. The update changes input device handling -- X will not start afterwards without user intervention; changes to xorg.conf are necessary. However, without fail, dozens of forum threads are opened after the update is released by users unable to start X.
Instead of immediately updating as soon as updates are available, users must recognize that an update to xorg-server may cause X not to start afterwards. This means that is not wise to update xorg-server if one is about to deliver an important presentation, for example. Rather, update during free time and be prepared to deal with any problems that may arise due to the update.
Next, a visit to the Arch Linux home page is always warranted. In this example, a news item was posted regarding the update which linked to a ArchWiki page that described how to reconfigure X. Often when updates to "critical" packages require user intervention, an appropriate update to http://archlinux.org will be made. Normally there will be forum posts describing the very same issue shortly after the update becomes available across the mirrors, detailing the solution any "problems".
When the actual update is performed, be sure to read the messages printed out by pacman. Packagers often describe the changes and the expected problems, and direct the users to the appropriate ArchWiki page. Always read all information output by pacman!
Querying package databases
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
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
To display extensive information about a given package:
$ pacman -Si package
for locally installed packages:
$ pacman -Qi package
To retrieve a list of the files installed by a package:
$ pacman -Ql package
One can also query the database to know which package a file on the file system belongs to.
$ pacman -Qo /path/to/a/file
To list all packages no longer required as dependencies (orphans):
$ pacman -Qdt
Additional commands
Download a package without installing it:
# pacman -Sw package
Install a 'local' package that is 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
Clean the entire package cache:
# pacman -Scc
Troubleshooting
Q: An update to package XYZ broke my system!
The most important tip to remember is to not "blindly" update your system. Always read the list of packages to be updated. Note whether "critical" packages are going to be updated (kernel26, xorg-server, klibc, and so on). If so, it is usually a good idea to check for any news at http://archlinux.org and scan recent forum posts to see if people are experiencing problems as a result of an update.
If a package update is expected/known to cause problems, packagers will ensure that pacman displays an appropriate message when the package is updated. If experiencing trouble after an update, always double-check your pacman logs (/var/log/pacman.log) for related messages.
At this point, only after ensuring there is no information available through pacman, there is no relative news on http://archlinux.org, and there are no forum posts regarding the update, you should consider seeking help on the forum, over IRC, or downgrading the offending package.
Re-read the last paragraph.Q: I know an update to package ABC was released, but pacman says my system is up to date!
Q: I get an error when updating: "file exists in filesystem"!
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.
Why this is happening: pacman has detected a file conflict, and by design, will not overwrite files for you. This is a design feature, not a flaw.
It is the user's responsibility to maintain their system, not the package manager's. (pacman -Qo may be invoked to query which package owns the file, if any.)
The issue is usually trivial to solve. A safe way is to first check if another package owns the file (pacman -Qo /path/to/file). If the file is owned by another package, file a bug report. If the file is not owned by another package, rename the file which 'exists in filesystem' and re-issue the update command. If all goes well, the file may then be removed.Q: I get an error when installing a package: "not found in sync db"
Q: pacman is repeatedly upgrading the same package!
Solution: delete the offending entry in /var/lib/pacman/local/.
Q: pacman crashes during an upgrade!
- Boot using the Arch live CD
- Mount your root filesystem
- Update the pacman database via pacman -Syy
- Reinstall the broken package via pacman -r /path/to/root -S package