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

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

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.

Usage

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:

有时候在不同的软件仓库中,一个软件包有多个版本(比如extra和testing)。你可以选择一个来安装:

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能够只用一个指令来升级系统中所有已安装的包。升级的时间取决于你的系统有多新。

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.

#!/bin/bash

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

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
fi

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
fi

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

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

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.

Configuration

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.

Repositories

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.

[repository-name]
Server = ftp://server.net/repo
[current]
# 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
rucksack
Pacman GUI Frontends