Arch Linux Pacman 命令详解

  • A+
所属分类:Remark

Pacman 包管理器是 Arch Linux 的一大亮点。它将一个简单的二进制包格式和易用的构建系统结合了起来。不管软件包是来自官方的 Arch 库还是用户自己创建,Pacman 都能方便得管理。
Pacman 通过和主服务器同步软件包列表来进行系统更新,这使得注重安全的系统管理员的维护工作成为轻而易举的事情。这种服务器/客户端模式可以使用一条命令就下载/安装软件包,同时安装必需的依赖包。(备注:以上来源于百度百科)
常用命令:
一、更新系统

pacman -Syu ---- 更新软件包列表后升级所有包;

二、安装软件

pacman -S package ---- 安装名称为package的软件;
pacman -Sy package ---- 同步包数据库后进行package的安装;
pacman -Sv package ---- 显示一些操作信息后执行安装;

三、删除软件

pacman -R package ---- 该命令将只删除包,不包含该包的依赖;
pacman -Rs package ---- 在删除包的同时,也将删除其依赖;
pacman -Rd package ---- 在删除包时不检查依赖;

OPERATIONS:(操作)

pacman -D(--database) ---- Modify the package database. This operation allows you to modify certain attributes of the installed packages in pacman’s database. At the moment, you can only change the install reason using --asdeps and --asexplicit options.

pacman -D(--database) ---- 可以修改已经安装软件在pacman的某些属性;

pacman -Q(--query) ---- Query the package database. This operation allows you to view installed packages and their files, as well as meta-information about individual packages (dependencies, conflicts, install date, build date, size). This can be run against the local package database or can be used on individual .tar.gz packages. In the first case, if no package names are provided in the command line, all installed packages will be queried. Additionally, various filters can be applied on the package list. See Query Options below.

pacman -Q(--query) ---- 查询软件包数据库;

pacman -R(--remove) ---- Remove package(s) from the system. Groups can also be specified to be removed, in which case every package in that group will be removed. Files belonging to the specified package will be deleted, and the database will be updated.Most configuration files will be saved with a .pacsave extension unless the --nosave option is used. See Remove Options below.

pacman -R(--remove) ---- 从系统删除软件;

pacman -S(--sync) ---- Synchronize packages. Packages are installed directly from the ftp servers, including all dependencies required to run the packages. For example, pacman -S qt will download and install qt and all the packages it depends on. If a package name exists in more than one repo, the repo can be explicitly specified to clarify the package to install: pacman -S testing/qt. You can also specify version requirements: pacman -S "bash>=3.2". (Quotes are needed, otherwise your shell interprets ">" as redirection to file.)
In addition to packages, groups can be specified as well. For example, if gnome is a defined package group, then
pacman -S gnome will provide a prompt allowing you to select which packages to install from a numbered list. The
package selection is specified using a space and/or comma separated list of package numbers. Sequential packages may
be selected by specifying the first and last package numbers separated by a hyphen (-). Excluding packages is achieved by prefixing a number or range of numbers with a caret (^).Packages that provide other packages are also handled. For example, pacman -S foo will first look for a foo package.If foo is not found, packages that provide the same functionality as foo will be searched for. If any package is found, it will be installed. A selection prompt is provided if multiple packages providing foo are found.You can also use pacman -Su to upgrade all packages that are out of date. See Sync Options below. When upgrading,pacman performs version comparison to determine which packages need upgrading. This behavior operates as follows:
Alphanumeric:
1.0a < 1.0b < 1.0beta < 1.0p < 1.0pre < 1.0rc < 1.0 < 1.0.a < 1.0.1 Numeric: 1 < 1.0 < 1.1 < 1.1.1 < 1.2 < 2.0 < 3.0.0 Additionally, version strings can have an epoch value defined that will overrule any version comparison (unless the epoch values are equal). This is specified in an epoch:version-rel format. For example, 2:1.0-1 is always greater than1:3.6-1. pacman -S(--sync) ---- 安装软件包; pacman -T(--deptest) ---- Check dependencies; this is useful in scripts such as makepkg to check installed packages. This operation will check each dependency specified and return a list of dependencies that are not currently satisfied on the system. This operation accepts no other options. Example usage: pacman -T qt "bash>=3.2".

pacman -T(--deptest) ---- 查看依赖(用于脚本);

pacman -U(--upgrade) ---- Upgrade or add package(s) to the system and install the required dependencies from sync repos. Either a URL or file path can be specified. This is a “remove-then-add” process. See Upgrade Options below; also see Handling Config Files for an explanation on how pacman takes care of config files.

pacman -U(--upgrade) ---- 升级软件包,删除重新安装过程;

pacman -V(--version) ---- Display version and exit.

pacman -h(--help) ---- Display syntax for the given operation. If no operation was supplied then the general syntax is shown.

OPTIONS:(选项)

pacman -b(--dbpath) ---- Specify an alternative database location (a typical default is /var/lib/pacman). This should not be used unless you know what you are doing. NOTE: if specified, this is an absolute path and the root path is not automatically prepended.

pacman -b(--dbpath) ---- 指定备份数据库位置;

pacman -r(--root) ---- Specify an alternative installation root (default is /). This should not be used as a way to install software into /usr/local instead of /usr. This option is used if you want to install a package on a temporary mounted partition that is "owned" by another system. NOTE: if database path or logfile are not specified on either the command line or in pacman.conf(5), their default location will be inside this root path.

pacman -r(--root) ---- 指定替代目录、默认是根目录;

pacman -v(--verbose) ---- Output paths such as as the Root, Conf File, DB Path, Cache Dirs, etc.

pacman -v(--verbose) ---- 显示配置文件信息;

pacman --arch ---- Specify an alternate architecture.

pacman --cachedir

---- Specify an alternative package cache location (a typical default is /var/cache/pacman/pkg). Multiple cache directories can be specified, and they are tried in the order they are passed to pacman. NOTE: this is an absolute path, the root path is not automatically prepended.

pacman --cachedir

---- 指定包缓存位置,默认(/var/cache/pacman/pkg);

pacman --color ---- Specify when to enable coloring, can be always, never or auto. Always forces colours on, never forces colours off, and auto only automatically enables colours when outputting onto a tty.

pacman --color ---- (指定颜色、参数有always、never、auto)

pacman --config ---- Specify an alternate configuration file.

pacman --config ---- 指定配置文件

pacman --debug ---- Display debug messages. When reporting bugs, this option is recommended to be used.

pacman --gpgdir

---- Specify a directory of files used by GnuPG to verify package signatures (a typical default is /etc/pacman.d/gnupg).This directory should contain two files: pubring.gpg and trustdb.gpg. pubring.gpg holds the public keys of all packagers. trustdb.gpg contains a so-called trust database, which specifies that the keys are authentic and trusted.
NOTE: this is an absolute path, the root path is not automatically prepended.

pacman --gpgdir

---- 安全相关;

pacman --logfile ---- Specify an alternate log file. This is an absolute path, regardless of the installation root setting.

pacman --noconfirm ---- Bypass any and all “Are you sure?” messages. It’s not a good idea to do this unless you want to run pacman from a script.

pacman --noconfirm ---- 取消确认信息;

TRANSACTION OPTIONS (APPLY TO -S, -R AND -U):配合选项

pacman -d, --nodeps ---- Skips dependency version checks. Package names are still checked. Normally, pacman will always check a package’s dependency fields to ensure that all dependencies are installed and there are no package conflicts in the system.Specify this option twice to skip all dependency checks.

pacman -d, --nodeps ---- 跳过依赖性检查,直接安装

pacman --dbonly ---- Adds/Removes the database entry only, leaves all files in place.

pacman --dbonly ---- 增加、删除数据库条目,但是保留文件;

pacman --noprogressbar ---- Do not show a progress bar when downloading files. This can be useful for scripts that call pacman and capture the output.

pacman --noprogressbar ---- 静默安装;

pacman --noscriptlet ---- If an install scriptlet exists, do not execute it. Do not use this unless you know what you are doing.

pacman --noscriptlet ---- ???

pacman -p(--print) ---- Only print the targets instead of performing the actual operation (sync, remove or upgrade). Use --print-format to specify how targets are displayed. The default format string is "%l", which displays URLs with -S, filenames with -U and pkgname-pkgver with -R.

pacman -p(--print) ---- 只打印,不执行;

pacman --print-format ---- Specify a printf-like format to control the output of the --print operation. The possible attributes are: %n for pkgname, %v for pkgver, %l for location, %r for repo and %s for size.

pacman --print-format ---- 指定打印格式;

UPGRADE OPTIONS (APPLY TO -S AND -U):升级参数

pacman --force ---- Bypass file conflict checks and overwrite conflicting files. If the package that is about to be installed contains files that are already installed, this option will cause all those files to be overwritten. Using --force will not allow overwriting a directory with a file or installing packages with conflicting files and directories. This option should be used with care, ideally not at all.

pacman --force ---- 覆盖安装选项;

pacman --asdeps ---- Install packages non-explicitly; in other words, fake their install reason to be installed as a dependency. This is useful for makepkg and other build from source tools that need to install dependencies before building the package.

pacman --asexplicit ---- Install packages explicitly; in other words, fake their install reason to be explicitly installed. This is useful if you want to mark a dependency as explicitly installed so it will not be removed by the --recursive remove operation.

pacman --ignore ---- Directs pacman to ignore upgrades of package even if there is one available. Multiple packages can be specified by separating them with a comma.

pacman --ignoregroup ---- Directs pacman to ignore upgrades of all packages in group even if there is one available. Multiple groups can be specified by separating them with a comma.

pacman --needed ---- Do not reinstall the targets that are already up to date.

QUERY OPTIONS:查询选项

pacman -c(--changelog) ---- View the ChangeLog of a package if it exists.

pacman -d(--deps) ---- Restrict or filter output to packages installed as dependencies. This option can be combined with -t for listing real orphans - packages that were installed as dependencies but are no longer required by any installed package.

pacman -e(--explicit) ---- Restrict or filter output to explicitly installed packages. This option can be combined with -t to list explicitly installed packages that are not required by any other package.

pacman -g(--groups) ---- Display all packages that are members of a named group. If a name is not specified, list all grouped packages.

pacman -i(--info) ---- Display information on a given package. The -p option can be used if querying a package file instead of the local database. Passing two --info or -i flags will also display the list of backup files and their modification states.

pacman -k(--check) ---- Check that all files owned by the given package(s) are present on the system. If packages are not specified or filter flags are not provided, check all installed packages. Specifying this option twice will perform more detailed file checking (including permissions, file sizes and modification times) for packages that contain the needed mtree file.

pacman -l(--list) ---- List all files owned by a given package. Multiple packages can be specified on the command line.

pacman -m(--foreign) ---- Restrict or filter output to packages that were not found in the sync database(s). Typically these are packages that were downloaded manually and installed with --upgrade.

pacman -n(--native) ---- Restrict or filter output to packages that are found in the sync database(s). This is the inverse filter of --foreign.

pacman -o(--owns) ---- Search for packages that own the specified file(s). The path can be relative or absolute and one or more files can be specified.

pacman -p(--file) ---- Signifies that the package supplied on the command line is a file and not an entry in the database. The file will be decompressed and queried. This is useful in combination with --info and --list.

pacman -q(--quiet) ---- Show less information for certain query operations. (This is useful when pacman’s output is processed in a script.) Search will only show package names and not version, group, and description information; owns will only show package names instead of "file is owned by pkg" messages; group will only show package names and omit group names; list will only show files and omit package names; check will only show pairs of package names and missing files; a bare query will only show package names rather than names and versions.

pacman -s(--search) ---- Search each locally-installed package for names or descriptions that match regexp. When including multiple search terms, only packages with descriptions matching ALL of those terms are returned.

pacman -t(--unrequired) ---- Restrict or filter output to packages not required by any currently installed package.

pacman -u(--upgrades) ---- Restrict or filter output to packages that are out of date on the local system. (Only package versions are used to find outdated packages, replacements are not checked here.) This option works best if the sync database is refreshed using -Sy.

REMOVE OPTIONS:

pacman -c(--cascade) ---- Remove all target packages, as well as all packages that depend on one or more target packages. This operation is recursive, and must be used with care since it can remove many potentially needed packages.

pacman -n(--nosave) ---- Instructs pacman to ignore file backup designations. Normally, when a file is removed from the system the database is checked to see if the file should be renamed with a .pacsave extension.

pacman -s(--recursive) Remove each target specified including all of their dependencies, provided that (A) they are not required by other packages; and (B) they were not explicitly installed by the user. This operation is recursive and analogous to a backwards --sync operation, and helps keep a clean system without orphans. If you want to omit condition (B), pass this option twice.

pacman -u(--unneeded) ---- Removes targets that are not required by any other packages. This is mostly useful when removing a group without using the -c option, to avoid breaking any dependencies.

SYNC OPTIONS

pacman -c(--clean) ---- Remove packages that are no longer installed from the cache as well as currently unused sync databases to free up disk space. When pacman downloads packages, it saves them in a cache directory. In addition, databases are saved for every sync DB you download from, and are not deleted even if they are removed from the configuration file pacman.conf(5). Use one --clean switch to only remove packages that are no longer installed; use two to remove all files from the cache. In both cases, you will have a yes or no option to remove packages and/or unused downloaded databases. If you use a network shared cache, see the CleanMethod option in pacman.conf(5).

pacman -g(--groups) ---- Display all the members for each package group specified. If no group names are provided, all groups will be listed; pass the flag twice to view all groups and their members.

pacman -i(--info) Display information on a given sync database package. Passing two --info or -i flags will also display those packages in all repositories that depend on this package.

pacman -l(--list) ---- List all packages in the specified repositories. Multiple repositories can be specified on the command line.

pacman -q(--quiet) ---- Show less information for certain sync operations. (This is useful when pacman’s output is processed in a script.) Search will only show package names and not repo, version, group, and description information; list will only show package names and omit databases and versions; group will only show package names and omit group names.

pacman -s(--search) ---- This will search each package in the sync databases for names or descriptions that match regexp. When you include multiple search terms, only packages with descriptions matching ALL of those terms will be returned.

pacman -u(--sysupgrade) Upgrades all packages that are out of date. Each currently-installed package will be examined and upgraded if a newer package exists. A report of all packages to upgrade will be presented and the operation will not proceed without user confirmation. Dependencies are automatically resolved at this level and will be installed/upgraded if necessary. Pass this option twice to enable package downgrade; in this case pacman will select sync packages whose version does not match with the local version. This can be useful when the user switches from a testing repo to a stable one. Additional targets can also be specified manually, so that -Su foo will do a system upgrade and install/upgrade the foo package in the same operation.

pacman -w(--downloadonly) ---- Retrieve all packages from the server, but do not install/upgrade anything.

pacman -y(--refresh) ---- Download a fresh copy of the master package list from the server(s) defined in pacman.conf(5). This should typically be used each time you use --sysupgrade or -u. Passing two --refresh or -y flags will force a refresh of all package lists even if they appear to be up to date.

参考文档:https://www.archlinux.org/pacman/pacman.8.html

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: