< Pacman (简体中文)

Pacman (简体中文)/Rosetta (简体中文)

这个页面用表格展示一些流行的 Linux 发行版包管理器命令的对应关系。这是受到 openSUSE's Software Management Command Line Comparison 的启发而成的。

提示: Arch 用户在临时处理其他发行版时可以用 pacapt,它是对其它包管理器的简单包装。
注意: 这里描述的一些工具只针对特定版本的 pacman。其中的 -Qk 选项是在 pacman 4.1 中新实现的。
翻译状态:本文是 Pacman/Rosetta翻译。上次翻译日期:2017-08-07。如果英文版本有所更改,则您可以帮助同步翻译。

基本操作

动作 Arch Red Hat/Fedora Debian/Ubuntu SLES/openSUSE Gentoo
按名安装包pacman -Sdnf installapt installzypper install
zypper in
emerge -1O
按名移除包pacman -Rsdnf removeapt removezypper remove
zypper rm
emerge -C
通过软件名、描述、简短描述来搜索包。默认搜索域依工具不同而异。Mostly options bring tools on par.pacman -Ssdnf searchapt searchzypper search
zypper se [-s]
emerge -S
升级包(安装已有包的更新版本)pacman -Syudnf upgradeapt update && apt upgradezypper update zypper upemerge -u world
升级包(更新命令的另一种形式,可以进行更复杂形式的更新,例如发行版升级。当通常的更新命令会忽略软件更新时——例如依赖改变——本命令可以进行这些更新)pacman -Syudnf distro-syncapt update && apt dist-upgradezypper dupemerge -uDN world
清除本地缓存(可能允许通过选项控制要清除拿些东西;autoclean 只清除过时的信息)pacman -Sc
pacman -Scc
dnf clean allapt autoclean
apt clean
zypper cleaneclean distfiles
移除不再需要的依赖(例如当依赖某包的软件被移除)pacman -Qdtq | pacman -Rs -dnf autoremoveapt autoremovezypper rm -uemerge --depclean
移除不再处于任何仓库中的包pacman -Qm | pacman -Rs -package-cleanup --orphansaptitude purge '~o'
将作为依赖安装的包指定为手动安装pacman -D --asexplicitdnf mark installapt-mark manualemerge --select
将包作为依赖安装pacman -S --asdepsdnf install => dnf mark removeapt-mark autoemerge -1
仅下载而不解包或安装pacman -Swdnf downloadapt install --download-only (下载到缓存)
apt download (下载到当前目录)
zypper --download-onlyemerge --fetchonly
启动一个 shell 以便在一个会话中输入多个命令apt-config shellzypper shell
查看日志cat /var/log/pacman.logdnf historycat /var/log/dpkg.logcat /var/log/zypp/historylocated in /var/log/portage
获取当前系统所有软件包的状态(see /var/lib/pacman/local)(see /var/lib/rpm/Packages)apt-cache statsn/aemerge --info
包变更时发送邮件apt install apt-listchanges
Action Arch Red Hat/Fedora Debian/Ubuntu SUSE/openSUSE Gentoo

查询某个包的信息

Action Arch Red Hat/Fedora Debian/Ubuntu SLES/openSUSE Gentoo
显示包的全部或者部分信息。各种包管理工具默认显示的详细程度各不相同,但是可以通过设置选项使其一致。pacman -[S|Q]idnf list, dnf infoapt show / apt-cache policyzypper info zypper ifemerge -S; emerge -pv; eix
显示本地包信息,包括包名、版本、描述等。pacman -Qirpm -qidpkg -s / aptitude showzypper info; rpm -qiemerge -pv and emerge -S
显示远程包信息,包括包名、版本、描述等。pacman -Sidnf infoapt-cache show / aptitude showzypper infoemerge -pv and emerge -S
显示本地包提供的文件。pacman -Qlrpm -qldpkg -Lrpm -Qlequery files
显示远程包提供的文件。pacman -Fldnf repoquery -lapt-file list $patternpfl
查询提供某个文件的包。pacman -Qorpm -qf (installed only) or dnf provides (everything)dpkg -S / dlocatezypper search -fequery belongs
列出包中的文件。其他更复杂的命令亦可以提供该功能。pacman -Ql
pacman -Fl
dnf repoquery -ldpkg-query -Lrpm -qlequery files
查出文件是由哪一个包提供的,主要是为了检索特定文件。其他工具亦可通过搜索命令提供该功能。pacman -Fodnf providesapt-file searchzypper what-provides zypper wpequery belongs (only installed packages); pfl
在所有包中查找包含指定文件的包。auto-apt 提供该功能。pacman -Fsdnf providesapt-file searchzypper search -fequery belongs
显示包的更新日志。pacman -Qcrpm -q --changelogapt-get changelogrpm -q --changelogequery changes -f
Action Arch Red Hat/Fedora Debian/Ubuntu SUSE/openSUSE Gentoo

查询包列表

Action Arch Red Hat/Fedora Debian/Ubuntu SLES/openSUSE Gentoo
Search for package(s) by searching the expression in name, description, short description. What exact fields are being searched by default varies in each tool. Mostly options bring tools on par.pacman -Ssdnf searchapt searchzypper search zypper se [-s]emerge -S
Lists packages which have an update available. Note: Some provide special commands to limit the output to certain installation sources, others use options.pacman -Qudnf list updates, dnf check-updateapt-get upgrade -> nzypper list-updates zypper patch-check (just for patches)emerge -uDNp world
Display a list of all packages in all installation sources that are handled by the packages management. Some tools provide options or additional commands to limit the output to a specific installation source.pacman -Sldnf list availableapt-cache dumpavail apt-cache dump (Cache only) apt-cache pkgnameszypper packagesemerge -ep world
Generates a list of installed packagespacman -Qdnf list installeddpkg --list | grep ^izypper search --installed-onlyemerge -ep world
List packages that are installed but are not available in any installation source (anymore).pacman -Qmdnf list extrasdeborphanzypper se -si | grep 'System Packages'eix-test-obsolete
List packages that were recently added to one of the installation sources, i.e. which are new to it.(none)dnf list recentaptitude search '~N' / aptitude forget-newn/aeix-diff
List installed local packages along with versionpacman -Qrpm -qadpkg -lzypper search -s; rpm -qaemerge -e world
Search locally installed package for names or descriptionspacman -Qsrpm -qa '*<str>*'aptitude search '~i(~n $name|~d $description)'eix -S -I
List packages not required by any other packagepacman -Qtpackage-cleanup --all --leavesdeborphan -anp1
List packages installed explicitly (not as dependencies)pacman -Qeapt-mark showmanual
List packages installed automatically (as dependencies)pacman -Qdapt-mark showauto
Action Arch Red Hat/Fedora Debian/Ubuntu SUSE/openSUSE Gentoo

查询包的依赖关系

Action Arch Red Hat/Fedora Debian/Ubuntu SLES/openSUSE Gentoo
Display packages which require X to be installed, aka show reverse dependencies.pacman -Siidnf repoquery --alldeps --whatrequiresapt-cache rdepends / aptitude search ~D$patternzypper search --requiresequery depends
Display packages which conflict with given expression (often package). Search can be used as well to mimic this function.dnf repoquery --conflictsaptitude search '~C$pattern'
List all packages which are required for the given package, aka show dependencies.pacman -[S|Q]idnf repoquery --requiresapt-cache depends / apt-cache showzypper info --requiresemerge -ep
List what the current package providesdnf providesdpkg -s / aptitude showzypper info --providesequery files
List all packages that require a particular packagednf repoquery --alldeps --whatrequiresaptitude search ~D{depends,recommends,suggests}:$pattern / aptitude whyzypper search --requiresequery depends -a
Display all packages that the specified packages obsoletes.dnf list obsoletesapt-cache show
Generates an output suitable for processing with dotty for the given package(s).apt-cache dottyn/a
Action Arch Red Hat/Fedora Debian/Ubuntu SUSE/openSUSE Gentoo

管理软件源

Action Arch Red Hat/Fedora Debian/Ubuntu SLES/openSUSE Gentoo
Installation sources management${EDITOR} /etc/pacman.conf${EDITOR} /etc/yum.repos.d/${REPO}.repo${EDITOR} /etc/apt/sources.list${EDITOR} /etc/zypp/repos.d/${REPO}.repolayman
Add an installation source to the system. Some tools provide additional commands for certain sources, others allow all types of source URI for the add command. Again others, like apt and dnf force editing a sources list. apt-cdrom is a special command, which offers special options design for CDs/DVDs as source./etc/pacman.conf/etc/yum.repos.d/*.repoapt-cdrom addzypper service-addlayman, overlays
Refresh the information about the specified installation source(s) or all installation sources.pacman -Sy (always upgrade the whole system afterwards)dnf clean expire-cache && dnf check-updateapt-get updatezypper refresh zypper refemerge --sync;layman -S
Prints a list of all installation sources including important information like URI, alias etc.cat /etc/pacman.d/mirrorlistcat /etc/yum.repos.d/*apt-cache policyzypper service-listlayman -l
Disable an installation source for an operationdnf --disablerepo=emerge package::repo-to-use
Download packages from a different version of the distribution than the one installed.dnf --releasever=apt-get install -t release package/ apt-get install package/release (deps not covered)echo "category/package ~amd64" >> /etc/portage/package.keywords && emerge package
Action Arch Red Hat/Fedora Debian/Ubuntu SUSE/openSUSE Gentoo

Overrides

Action Arch Red Hat/Fedora Debian/Ubuntu SLES/openSUSE Gentoo
增加包锁定规则来保持其当前状态不被改变/etc/pacman.conf
modify IgnorePkg array
dnf.conf <--”exclude” option (add/amend)apt-mark hold pkgPut package name in /etc/zypp/locks, or zypper al/etc/portage/package.mask
删除包锁定规则remove package from IgnorePkg line in /etc/pacman.confapt-mark unhold pkgRemove package name from /etc/zypp/locks or zypper rl/etc/portage/package.mask (or package.unmask)
列出所有锁定规则cat /etc/pacman.conf/etc/apt/preferencesView /etc/zypp/locks or zypper llcat /etc/portage/package.mask
Set the priority of the given package to avoid upgrade, force downgrade or to overwrite any default behavior. Can also be used to prefer a package version from a certain installation source.${EDITOR} /etc/pacman.conf
Modify HoldPkg and/or IgnorePkg arrays
/etc/apt/preferences, apt-cache policyzypper mr -p${EDITOR} /etc/portage/package.keywords
Add a line with =category/package-version
Remove a previously set priority/etc/apt/preferenceszypper mr -p${EDITOR} /etc/portage/package.keywords
remove offending line
Show a list of set priorities.apt-cache policy /etc/apt/preferenceszypper lr -pcat /etc/portage/package.keywords
Ignores problems that priorities may trigger.n/a
Action Arch Red Hat/Fedora Debian/Ubuntu SUSE/openSUSE Gentoo

校验和修复

Action Arch Red Hat/Fedora Debian/Ubuntu SLES/openSUSE Gentoo
Verify single packagepacman -Qk[k]rpm -Vdebsumsrpm -Vequery check
Verify all packagespacman -Qk[k]rpm -Vadebsumsrpm -Vaequery check
Reinstall given Package - Will reinstall the given package without dependency hassle.pacman -Sdnf reinstallapt install --reinstallzypper install --forceemerge [-a]
Verify dependencies of the complete system. Used if installation process was forcefully killed.pacman -Dkdnf repoquery --requiresapt-get checkzypper verifyemerge -uDN world
Use some magic to fix broken dependencies in a systempacman dep level - pacman -Dk, shared lib level - findbrokenpkgs or lddddnf repoquery --unsatisfiedapt-get --fix-broken
aptitude install
zypper verifyrevdep-rebuild
为包系统增加一个检查点以便未来回滚(unnecessary, done on every transaction)n/a
删除系统中的一个检查点N/AN/An/a
提供所有系统检查点的列表N/Adnf history listn/a
将所有包滚回特定日期或检查点N/Adnf history rollbackn/a
撤销特定改动N/Adnf history undon/a
Action Arch Red Hat/Fedora Debian/Ubuntu SUSE/openSUSE Gentoo

使用软件包文件和构建软件包

Action Arch Red Hat/Fedora Debian/Ubuntu SLES/openSUSE Gentoo
Query a package supplied on the command line rather than an entry in the package management databasepacman -Qprpm -qpdpkg -I
List the contents of a package filepacman -Qplrpmls rpm -qpldpkg -crpm -qpl
Installs local package file, e.g. app.rpm and uses the installation sources to resolve dependenciespacman -Udnf installapt installzypper inemerge
Updates package(s) with local packages and uses the installation sources to resolve dependenciespacman -Udnf upgradedebiemerge
Add a local package to the local package cache mostly for debugging purposes.cp $filename /var/cache/pacman/pkg/apt-cache addn/acp $filename /usr/portage/distfiles
解包tar -Jxvfrpm2cpio | cpio -viddpkg-deb -xrpm2cpio | cpio -vidtar -jxvf
安装/移除包以适合构建依赖(使用源码包中的信息)automaticdnf builddepapt-get build-depzypper si -demerge -o
Display the source package to the given package name(s)dnf repoquery -sapt-cache showsrcn/a
Downloads the corresponding source package(s) to the given package name(s)Use ABS && makepkg -odnf download --sourceapt-get source / debcheckoutzypper source-installemerge --fetchonly
Build a packagemakepkg -srpmbuild -ba (normal)
mock (in chroot)
debuildrpmbuild -ba; build; osc buildebuild; quickpkg
Check for possible packaging issuesnamcaprpmlintlintianrpmlintrepoman
Action Arch Red Hat/Fedora Debian/Ubuntu SUSE/openSUSE Gentoo

参阅

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.