参考来源: http://distrowatch.com
版权所有: Copyright © 2016 DistroWatch.com.
个人认为包管理器代表着该发行版的文化,是其核心。曾经看到一个算是笑话吧,一个人移植portage到lfs上然后用着用着就变成了gentoo了。所以包管理器是发行版的灵魂,以下列举一些常见包管理器的简单实用命令
Introduction
Package management is probably the most distinctive feature of any Linux distribution. While the current trend among most of the major projects is to offer some sort of a clickable interface where users can select a package and install it with a mouse click (e.g. Debian’s Synaptic or Mandriva’s Drakrpm), these types of programs are generally just graphical front-ends to the low-level utilities that manage the tasks associated with installing packages on a Linux system. And even though many desktop Linux users feel much more comfortable installing packages through these intuitive graphical tools, there is no denying that command-line package management offers two excellent features not available in any graphical package management utility: power and speed.
One problem that many distro-hoppers and operating system enthusiasts encounter is having to master (or relearn) a set of package management commands each time they switch from one distribution group to another. Additionally, the package management tools tend to evolve, with new features and even new commands added to every new version. This is why we created this package management cheatsheet - an easy reference card covering most frequently used package management tasks in Linux distributions and FreeBSD.
首先比较ubuntu和red hat的包管理器 (如果你觉得文章太长的话可以只看这一个表就可以了)
Task | Red Hat/Fedora | Ubuntu |
Adding, Removing and Upgrading Packages | ||
Refresh list of available packages | Yum refreshes each time it's used | apt-get update |
Install a package from a repository | yum install package_name | apt-get install package_name |
Install a package file | yum install package.rpm | dpkg --install package.deb |
Remove a package | rpm -e package_name | apt-get remove package_name |
Check for package upgrades | yum check-update | apt-get -s upgrade |
Upgrade packages | yum update | apt-get upgrade |
Upgrade the entire system | yum upgrade | apt-get dist-upgrade |
Package Information | ||
Get information about an available package | yum search package_name | apt-cache search package_name |
Show available packages | yum list available | apt-cache dumpavail |
List all installed packages | yum list installed | dpkg --list |
Get information about a package | yum info package_name | apt-cache show package_name |
Get information about an installed package | rpm -qi package_name | dpkg --status package_name |
List files in an installed package | rpm -ql package_name | dpkg --listfiles package_name |
List documentation files in an installed package | rpm -qd package_name | - |
List configuration files in an installed package | rpm -qc package_name | dpkg-query --show -f '${Conffiles}\n'package_name |
Show the packages a given package depends on | rpm -qR package_name | apt-cache depends |
Show other packages that depend on a | rpm -q -whatrequires [args] | apt-cache rdepends |
Package File Information | ||
Get information about a package file | rpm -qpi package.rpm | dpkg --info package.deb |
List files in a package file | rpm -qpl package.rpm | dpkg --contents package.deb |
List documentation files in a package file | rpm -qpd package.rpm | - |
List configuration files in a package file | rpm -qpc package.rpm | - |
Extract files in a package | rpm2cpio package.rpm | cpio -vid | dpkg-deb --extract package.deb dir-to-extract-to |
Find package that installed a file | rpm -qf filename | dpkg --search filename |
Find package that provides a particular file | yum provides filename | apt-file search filename |
Misc. Packaging System Tools | ||
Show stats about the package cache | - | apt-cache stats |
Verify all installed packages | rpm -Va | debsums |
Remove packages from the local cache directory | yum clean packages | apt-get clean |
Remove only obsolete packages from the local cache directory | - | apt-get autoclean |
Remove header files from the local cache directory | yum clean headers | apt-file purge |
General Packaging System Information | ||
Package file extension | *.rpm | *.deb |
Repository location configuration | /etc/yum.conf | /etc/apt/sources.list
|
第一个表列出比较常见的发行版的包管理器(apt,yum) fedora从22开始使用dnf作为包管理器,使用方法大致相同;ubuntu从16.04开始实验测试使用snap包管理器,这里未做介绍(留作feture吧)
Task | apt (deb) Debian, Ubuntu | zypp (rpm) openSUSE | yum/dnf (rpm) Fedora, CentOS | urpmi (rpm) Mandriva, Mageia |
---|---|---|---|---|
Managing software | ||||
Install new software from package repository | apt-get install pkg | zypper install pkg | yum install pkg | urpmi pkg |
Install new software from package file | dpkg -i pkg | zypper install pkg | yum localinstall pkg | urpmi pkg |
Update existing software | apt-get install pkg | zypper update -t package pkg | yum update pkg | urpmi pkg |
Remove unwanted software | apt-get remove pkg | zypper remove pkg | yum erase pkg | urpme pkg |
Updating the system | ||||
Update package list | apt-get update aptitude update | zypper refresh | yum check-update | urpmi.update -a |
Update system | apt-get upgrade aptitude safe-upgrade | zypper update | yum update | urpmi --auto-select |
Searching for packages | ||||
Search by package name | apt-cache search pkg | zypper search pkg | yum list pkg | urpmq pkg |
Search by pattern | apt-cache search pattern | zypper search -t pattern pattern | yum search pattern | urpmq --fuzzy pkg |
Search by file name | apt-file search path | zypper wp file | yum provides file | urpmf file |
List installed packages | dpkg -l | zypper search -is | rpm -qa | rpm -qa |
Configuring access to software repositories | ||||
List repositories | cat /etc/apt/sources.list | zypper repos | yum repolist | urpmq --list-media |
Add repository | (edit /etc/apt/sources.list) | zypper addrepo path name | (add repo to /etc/yum.repos.d/) | urpmi.addmedia name path |
Remove repository | (edit /etc/apt/sources.list) | zypper removerepo name | (remove repo from /etc/yum.repos.d/) | urpmi.removemedia media |
基于Slackware和Slackware的发行版 对于这个分支 本人不是特别了解 暂时不做解释
Task | pkgtools Slackware | slackpkg Slackware | slapt-get Vector | netpkg Zenwalk |
---|---|---|---|---|
Managing software | ||||
Install new software from package repository | -- | slackpkg install pkg | slapt-get --install pkg | netpkg pkg |
Install new software from package file | installpkg pkg | slackpkg install pkg | slapt-get --install pkg | netpkg pkg |
Update existing software | upgradepkg pkg | slackpkg upgrade pkg | slapt-get --install pkg | netpkg pkg |
Remove unwanted software | removepkg pkg | slackpkg remove pkg | slapt-get --remove pkg | netpkg remove pkg |
Updating the system | ||||
Update package list | -- | slackpkg update | slapt-get --update | (automatic) |
Update system | -- | slackpkg upgrade-all | slapt-get --upgrade | netpkg upgrade |
Searching for packages | ||||
Search by package name | -- | slackpkg search pkg | slapt-get --search pkg | netpkg pkg repo |
Search by pattern | -- | slackpkg search pattern | slapt-get --search pattern | netpkg list | grep pattern |
Search by file name | -- | -- | -- | netpkg file repo |
List installed packages | ls /var/log/packages/ | ls /var/log/packages/ | slapt-get --installed | netpk list I |
Configuring access to software repositories | ||||
List repositories | -- | cat /etc/slackpkg/mirrors | cat /etc/slapt-get/slapt-getrc | netpkg mirror |
Add repository | -- | (edit /etc/slackpkg/mirrors) | (edit /etc/slapt-get/slapt-getrc) | (edit /etc/netpkg.conf) |
Remove repository | -- | (edit /etc/slackpkg/mirrors) | (edit /etc/slapt-get/slapt-getrc) | (edit /etc/netpkg.conf) |
一些独立的Linux发行版 sabyon是作为gentoo的衍生版提供更多的二进制包,自己也有包管理器; arch和基于arch的Manjaro也是现在使用较多的发行版,轻量简洁高效,参考arch之道(链接没找到暂时拿主页凑合)
Task | equo Sabayon | pacman Arch | conary rPath, Foresight | apk Alpine |
---|---|---|---|---|
Managing software | ||||
Install new software from package repository | equo install pkg | pacman -S pkg | conary update pkg | apk add pkg |
Install new software from package file | equo install pkg | pacman -U pkg | conary update pkg | apk add --force pkg |
Update existing software | equo install pkg | pacman -S pkg | conary update pkg | apk add --upgrade pkg |
Remove unwanted software | equo remove pkg | pacman -R pkg | conary erase pkg | apk del pkg |
Updating the system | ||||
Update package list | equo update | pacman -Sy | apk update | |
Update system | equo upgrade | pacman -Su | conary updateall | apk upgrade |
Searching for packages | ||||
Search by package name | equo match pkg | pacman -Ss pkg | conary query pkg | apk search pkg |
Search by pattern | equo search pattern | pacman -Ss pattern | conary query pkg | apk search pattern |
Search by file name | equo belongs file | pacman -Qo file | conary query --path path | -- |
List installed packages | equo list | pacman -Q | conary query | apk info |
Configuring access to software repositories | ||||
List repositories | equo repoinfo | cat /etc/pacman.conf | cat /etc/apk/repositories | |
Add repository | (edit /etc/pacman.conf) | setup-apkrepos | ||
Remove repository | (edit /etc/pacman.conf) | (edit /etc/apk/repositories) |
Distribution Agnostic Package Management (不知道是啥,直接引用原版)
Besides standard package management utilities that most distributions use as part of their systems, there are also some distro-agnostic ones that have been deployed with various levels of success in certain distributions. Smart, originally developed by Conectiva, hasn’t been in the news lately, but some users seem to prefer it over Mandriva’s urpmi or openSUSE’s zypper (it also supports Debian and Slackware-based systems). More recently it is Fedora’s PackageKit that has been gaining momentum as a way to manage packages across distributions and architectures. Now included in many other distributions, PackageKit’s pkgcon command-line utility is effectively a unified front-end to the native package management tools of Fedora, Ubuntu, openSUSE, Mandriva and other distributions.
Task | smart Mandriva, openSUSE | pkgcon Fedora, Ubuntu, openSUSE, Mandriva |
---|---|---|
Managing software | ||
Install new software from package repository | smart install pkg | pkcon install pkg |
Install new software from package file | smart install pkg | pkcon install-file pkg |
Update existing software | smart install pkg | pkcon update pkg |
Remove unwanted software | smart remove pkg | pkcon remove pkg |
Updating the system | ||
Update package list | smart update | pkcon refresh |
Update system | smart upgrade | pkcon upgrade |
Searching for packages | ||
Search by package name | smart search pkg | pkcon search name pkg |
Search by pattern | smart search pattern | pkcon search details pattern |
Search by file name | smart query file | pkcon what-provides file |
List installed packages | smart query --installed | pkcon search name pkg | grep Installed |
Configuring access to software repositories | ||
List repositories | smart channel --show | pkcon repo-list |
Add repository | smart channel --add name path | |
Remove repository | smart channel --remove name |
基于源码的发行版 gentoo如果有比较多的时间和电脑配置还可以的话 可以试试,定制性很高。后来由gentoo创始人缔造的funtoo有些概念区别,个人感觉基本差不多
Task | portage Gentoo | lunar Lunar | sorcery Source Mage |
---|---|---|---|
Managing software | |||
Install new software from package repository | emerge pkg | lin pkg | cast pkg |
Install new software from package file | |||
Update existing software | emerge pkg | lin pkg | cast pkg |
Remove unwanted software | emerge -aC pkg | lrm pkg | dispel pkg |
Updating the system | |||
Update package list | emerge --sync | lin moonbase | scribe update |
Update system | emerge -NuDa world | lunar update | sorcery upgrade |
Searching for packages | |||
Search by package name | emerge --search pkg | lvu search pkg | gaze search -name pkg |
Search by pattern | emerge --search pattern | lvu search pattern | gaze search pattern |
Search by file name | equery belongs pkg | gaze from file | |
List installed packages | qlist -I | lvu installed | gaze installed |
Configuring access to software repositories | |||
List repositories | layman -L | -- | scribe index |
Add repository | layman -a repo | -- | scribe add repo |
Remove repository | layman -d repo | -- | scribe remove repo |
咦,这里有snap啊 不是很清楚 待编辑
Task | nix NixOS | xbps Void | snap Ubuntu |
---|---|---|---|
Managing software | |||
Install new software from package repository | nix-env -i pkg | xbps-install pkg | snap install pkg |
Install new software from package file | -- | -- | -- |
Update existing software | nix-env -u pkg | xbps-install -u pkg | snap refresh pkg |
Remove unwanted software | nix-env -e pkg | xbps-remove pkg | snap remove pkg |
Updating the system | |||
Update package list | nix-channel --update | xbps-install -S | -- |
Update system | nix-env -u | xbps-install -u | -- |
Searching for packages | |||
Search by package name | nix-env -qa pkg | xbps-query -Rs pkg | snap find pkg |
Search by pattern | nix-env -qa pattern | xbps-query -Rs pattern | snap find | grep pattern |
Search by file name | -- | xbps-query -o file | -- |
List installed packages | nix-env -q | xbps-query -l | snap list |
Configuring access to software repositories | |||
List repositories | nix-channel --list | xbps-query -L | -- |
Add repository | nix-channel --add url name | (add to /etc/xbps/repo.d/ or /usr/share/xbps/repo.d/) | -- |
Remove repository | nix-channel --remove name | (edit /etc/xbps/repo.d/ and /usr/share/xbps/repo.d/) | -- |
最后来个学院派的 freebsd,macos基于freebsd产生,其包管理器brew等我有了mac book再说吧(基本是没戏了 233333)
Task | packages FreeBSD < 10.0 | packages FreeBSD 10.0+ | ports FreeBSD |
---|---|---|---|
Managing software | |||
Install new software from package repository | pkg_add -r package | pkg install package | cd port_dir && make && make install |
Install new software from package file | pkg_add path_to_package | pkg add path_to_package | -- |
Update existing software | pkg_add path_to_package | pkg install path_to_package | portupgrade -R pkg |
Remove unwanted software | pkg_delete pkg | pkg remove pkg | pkg_delete pkg |
Updating the system | freebsd-update fetch install | freebsd-update fetch install | portsnap fetch install |
Update package list | pkg update | csup -L 2 -h cvsup.FreeBSD.org path_to_supfile portsnap update | |
Update system | pkg upgrade | portupgrade -a portmanager -u portmaster -a | |
Searching for packages | |||
Search by package name | pkg search package | cd /usr/ports && make search pkg | |
Search by pattern | pkg search pattern | cd /usr/ports && make search pattern | |
Search by file name | |||
List installed packages | pkg_info | pkg info | pkg_info |
Configuring access to software repositories | |||
List repositories | -- | -- | -- |
Add repository | -- | -- | -- |
Remove repository | -- | -- | -- |