Difference between revisions of "Pacman (简体中文)"

From ArchWiki
Jump to: navigation, search
(Add {{translateme}} for part of it has left untranslated.)
Line 16: Line 16:

Revision as of 00:45, 17 January 2008

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Pacman (简体中文)#)


Pacman包管理器是Arch Linux的一大亮点。它将一个简单的二进制包格式和易用的构建系统结合了起来(see ABS)。Pacman使得简单的管理与自定义软件包成为了可能,而不论他们来自于官方的Arch软件库或是用户自己创建的。软件库系统允许用户构建和维护他们自己的软件包仓库,这样可以鼓励社区的成长与贡献(see AUR)。

Pacman can keep a system up to date by synchronizing package lists with the master server, making it a breeze for the security-conscious system administrator to maintain. This server/client model also allows you to download/install packages with a simple command, complete with all required dependencies (similar to Debian's apt-get).

Pacman NB: Pacman was written and is being maintained by Judd Vinet, the creator of Arch Linux. But it is used as a package management tool by other distros as well, such as FrugalWare (see also [[1]]), Rubix, UfficioZero (in Italian, based on Ubuntu!!), and of course ArchLinux-derivatives such as Archie and AEGIS.


Pacman is both a binary and source package manager. It combines several ideas from FreeBSD, Debian and Slackware to form one of the most extensive yet easy to use package managers available for GNU/Linux. Pacman is able to download, install and upgrade packages from both remote and local repositories with full dependency handling, and has easy to understand tools for crafting your own packages too.

Pacman 包管理器能够管理二进制包和源码包。它吸取了FreeBSD、Debian和Slackware的经验,成为了GNU/Linux最具扩展性,容易使用的包管理器之一。Pacman能够远程或本地的软件仓库中下载、安装和升级软件包,并且完美地处理包依赖关系,同时拥有容易理解的制作包制作工具。

Installing and Removing Packages

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


pacman -Sy

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 more 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 combine parameters at once, for example this will both synchronize the package database and install a package:


pacman -Sy package_name

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


pacman -R package_name

To also remove all of the packages dependencies which aren't used by any other installed package:


pacman -Rs package_name

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

NB: you can synchronise the repository databases AND update your system in one go with

NB: 你也可以将升级系统和同步仓库数据合成为一条指令

pacman -Syu

It is actually good practice to run the above command every few days.


Querying the Package Database

Pacman can search the package database for a list of packages, you can enter part of the package name to search for all packages matching the string.

pacman -Ss package

To just search installed packages:

pacman -Qs package

Once you know the name of the package you are looking for, you can display some information on the package.

pacman -Si package  
pacman -Qi package

For a list of files contained in a package:

pacman -Ql package

You can also query what package a file on your system belongs to.

pacman -Qo /path/to/a/file

Simultaneously Searching Repositories and Installed Packages

You can use the following bash script to do the equivalent of simultaneously calling pacman -Ss foo and pacman -Qs foo, in order to see which of the packages listed are actually installed on your system. The latter will be flagged with an asterisk.


if [ -z "$1" ]; then
echo "usage: pacsearch [regex pattern]"
echo "usage: pacsearch -h|--help"
exit 0

if [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "usage: pacsearch [regex pattern]"
echo "	Like pacman -Ss [regex pattern] but installed packages are flagged with a *"
echo "usage: pacsearch -h|--help"
echo "	Prints this message. No other options allowed"
exit 0

firstchar=`echo "$1" | cut -c1`
if [ $firstchar = "-" ]; then
echo "Sorry, $1 is not a valid option!"
echo "usage: pacsearch [regex pattern]"
echo "usage: pacsearch -h|--help"
exit 0

instpkg=`pacman -Qs $1 | egrep '^[^ ]' | sed 's|^local/||' | sed 's/ .\+$//'` 
pacman -Ss $1 > $syncdump

for pkg in $instpkg; do
	sed -i "s@^\(.\+/$pkg\) @\*\1 @" $syncdump

cat $syncdump

Save the script somewhere in your path (e.g. ~/bin/) and name it pacsearch. Make it executable with

chmod a+x pacsearch

Now if you type for example

pacsearch ^qt

the output could look like this:

extra/qca 1.0-1
   QT Cryptography Architecture
extra/qsynth 0.2.5-1
   Qt GUI for fluidsynth
*extra/qt 3.3.5-8
   The QT gui toolkit.
extra/qt-doc 3.3.5-1
   The QT gui toolkit documentation.
extra/qtella 0.6.5-1
   Qtella is a Gnutella client for Linux using QT
extra/qtiplot 0.7.7-1
   Data analysis and scientific plotting - free clone of Origin
extra/qtparted 0.4.5-3
   A Partition Magic clone written in C++ using the Qt toolkit
extra/qwt 4.2.0-3
   Qt Widgets for Technical Applications
extra/qwtplot3d 0.2.6-2
   Qt/OpenGL-based C++ programming library containing 3d-widgets

So in this case you would know that none of the above packages are installed on your system except qt itself.

NB1: a request has been filed on flyspray to integrate the above functionality in pacman itself, so the 'dirty' bash trick might become superfluous with a future version of pacman.

NB2: you can modify the above bash script on the basis of this wiki to have installed packages colored differently in the output.

Other Usage

Pacman is quite an extensive package management tool, below are some other features.

  • Downloading a package without installing it:
pacman -Sw package_name
  • Installing a local package (not from repository):
pacman -A /path/to/package/package_name-version.pkg.tar.gz
  • Cleaning pacman's cache (/var/cache/pacman/pkg):
pacman -Scc

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


Pacman configuration is located in /etc/pacman.conf. There are two main sections in the file:

General options

General options are in [options] section. You can specify here which files should not be upgraded. This is useful for important system files. The syntax is very simple:

NoUpgrade   = etc/passwd etc/group etc/shadow etc/sudoers
NoUpgrade   = etc/fstab etc/raidtab etc/ld.so.conf
NoUpgrade   = etc/rc.conf etc/rc.local
NoUpgrade   = etc/modprobe.conf etc/modules.conf
NoUpgrade   = etc/lilo.conf boot/grub/menu.lst

Another useful option is IgnorePkg. For example if you have modified or patched a certain package, adding it to the IgnorePkg line will prevent pacman from upgrading it when a new version becomes available. But pacman will still warn you about the newest available version, so you can eventually decide to update your customized version. This option is also useful for LARGE packages like openoffice-base if you want to avoid downloading and updating the whole lot every time there is a minor update in the repository. Since pacman warns you about the latest version anyway, you can decide to upgrade manually if you wish.


In this section you define which repositories to use. They can be defined directly there or you can include them from another file. The latter is useful for the official repositories which have a lot of mirrors.

Server = ftp://server.net/repo
# Add your preferred servers here, they will be used first
Include = /etc/pacman.d/current

For more information please refer to man pacman.

Related links

Boost Pacman
Colored Pacman output
Downgrade packages
Redownloading all installed packages
Server configuration in pacman.conf
ArchLinux User-community Repository (AUR)
Local repository HOW-TO
Custom local repository with ABS and gensync
Howto Upgrade via Home Network
Pacman GUI Frontends