手机版 欢迎访问it开发者社区(www.mfbz.cn)网站

当前位置: > 开发

Linux: 软件包管理工具 yum/dnf 命令

时间:2021/5/26 0:44:43|来源:|点击: 次

本文链接: https://xiets.blog.csdn.net/article/details/117205082

1. yum 与 dnf

yum (Yellow dog Updater, Modified) 是基于 .rpm 的 Linux 发行版(Fedora/CentOS/RedHat)系统的 Shell 前端软件包管理工具。yum 支持查找、安装、卸载软件包等管理操作。yum 可以从指定的软件包仓库搜索、下载、安装软件包,并自动处理依赖关系,自动安装所有依赖包。执行 yum 命令需要管理员权限(root)。

dnf (Dandified YUM) 是 Yum 的下一代版本。DNF 于 Fedora 18 中引入,并在 Fedora22、RHEL8 和 CentOS8 中成为默认的软件包管理器。DNF 的命令行接口基本保持了与 Yum 相兼容,主要命令可以像使用 Yum 一样使用 DNF,后面还是以 Yum 为示例。

实际上在软件包管理器默认已为 DNF 的 Linux 系统上,Yum 命令已被重定向到了 DNF:

$ ls -l /usr/bin | grep "dnf"
lrwxrwxrwx 1 root root       5 Mar  2 15:57 dnf -> dnf-3
-rwxr-xr-x 1 root root    1942 Mar  2 15:57 dnf-3
lrwxrwxrwx 1 root root       5 Mar  2 15:57 yum -> dnf-3

相关网站:

  • Yum Commands Wiki: http://yum.baseurl.org/wiki/YumCommands.html
  • DNF Command Reference: https://dnf.readthedocs.io/en/latest/command_ref.html

其他 Linux 软件包管理工具:

  • apt (Debian/Ubuntu)
  • apk (Alpine Linux)
  • snap (All Linux)

后面的命令示例以 CentOS 8 系统为例。

2. 更新/安装 软件包

  • 更新
yum check-update                # 检查所有可用的软件包升级
yum check-update <package>      # 检查指定软件包是否可升级

yum upgrade                     # 升级所有软件包
yum upgrade <package>           # 升级指定软件包
  • 安装
yum install <package>           # 安装软件包
yum reinstall <package>         # 重新安装软件包

3. 卸载/清理 软件包

  • 卸载
yum remove <package>            # 卸载软件包
yum autoremove                  # 删除所有最初作为依赖项安装的不需要的软件包
  • 清理
yum clean packages              # 清除所有在可用仓库目录中缓存的所有软件包
yum clean dbcache               # Yum 使用时会创建一些 SQLite 数据库文件在可用的仓库中, 此命令将清楚缓存的副本
yum clean metadata              # 从可用仓库中清除所有缓存的 XML 元数据
yum clean expire-cache          # 清除过期的缓存
yum clean all                   # 从所有可用仓库中清除所有缓存文件(包括清除上面几条命令清理的若干数据)

4. 查询/搜索 软件包

  • 列出软件包 (list 命令)
# yum list 命令格式
yum list [available|installed|extras|updates|obsoletes|all|recent] [pkgspec]

# 参数说明:
#       available       列出所有可安装的软件包 (系统的可用仓库中)
#       installed       列出所有已安装的软件包
#       extras          列出所有已安装但已不再可用仓库中的软件包
#       updates         列出所有已安装的软件包在可用仓库中可更新的软件包, 类似 yum check-update
#       obsoletes       列出所有在可用软件包和已安装软件包之间过时的依赖关系
#       all             列出在软件包仓库(未安装)和已安装的所有软件包 (yum list 不加参数默认为 all 参数)
#       recent          列出过去 7 天内添加到可用仓库中的所有软件包
#
#       pkgspec         操作指定的软件包, 没有该指定则默认操作所有包


yum repolist                            # 列出已配置的软件包仓库
  • 查询软件包的详情信息
yum info <package>                      # 查询软件包的详细信息
  • 查询某个命令属于哪个软件包
yum whatprovides COMMAND
  • 搜索软件包
yum search <string>                     # 搜索软件包
yum search <string> | grep "package"    # 过滤搜索结果

5. 手动安装 rpm 软件包

rpm -i package.rpm                      # 离线安装已下载到本地的 rpm 软件包

6. yum 主要的命令

用法: yum [options] COMMAND

#COMMAND描述
1alias列出或创建命令别名
2autoremove删除所有最初作为依赖项安装的不需要的软件包
3check检查 packagedb 中的问题
4check-update检查可用的软件包升级
5clean删除缓存的数据
6deplist列出软件包的依赖关系以及哪些包提供这些依赖
7distro-sync将已安装的软件包同步到最新的可用版本
8downgrade降级软件包版本
9group显示或使用组信息
10help显示有用的使用信息
11history显示或使用 transaction 历史记录
12info显示关于一个软件包或组的详细信息
13install在系统上安装一个或多个软件包
14list列出一个软件包或组
15makecache生成元数据缓存
16mark将已安装的软件包标记或取消标记为用户安装的软件包
17module与模块进行交互
18provides根据提供的给定值找出软件包
19reinstall重新安装软件包
20remove从系统中删除一个或多个软件包
21repolist显示已配置的软件包仓库
22repoquery搜索与关键字匹配的软件包
23repository-packages在给定仓库中的所有软件包之上运行命令
24search根据给定字符串搜索软件包的详细信息
25shell运行一个交互式的 YUM Shell
26swap运行一个交互式的 YUM mod 以删除并安装一个规范
27updateinfo显示有关软件包的建议
28upgrade升级系统上的一个或多个软件包
29upgrade-minimal升级,但只匹配“最新”软件包,可以解决影响您系统的问题

每个子命令又可以使用 --help 查看命令的用法,如:

$ yum alias --help
...

7. yum --help

$ yum --help

usage: yum [options] COMMAND

List of Main Commands:

alias                     List or create command aliases
autoremove                remove all unneeded packages that were originally installed as dependencies
check                     check for problems in the packagedb
check-update              check for available package upgrades
clean                     remove cached data
deplist                   List package's dependencies and what packages provide them
distro-sync               synchronize installed packages to the latest available versions
downgrade                 Downgrade a package
group                     display, or use, the groups information
help                      display a helpful usage message
history                   display, or use, the transaction history
info                      display details about a package or group of packages
install                   install a package or packages on your system
list                      list a package or groups of packages
makecache                 generate the metadata cache
mark                      mark or unmark installed packages as installed by user.
module                    Interact with Modules.
provides                  find what package provides the given value
reinstall                 reinstall a package
remove                    remove a package or packages from your system
repolist                  display the configured software repositories
repoquery                 search for packages matching keyword
repository-packages       run commands on top of all packages in given repository
search                    search package details for the given string
shell                     run an interactive YUM shell
swap                      run an interactive YUM mod for remove and install one spec
updateinfo                display advisories about packages
upgrade                   upgrade a package or packages on your system
upgrade-minimal           upgrade, but only 'newest' package match which fixes a problem that affects your system

List of Plugin Commands:

builddep                  Install build dependencies for package or spec file
changelog                 Show changelog data of packages
config-manager            manage yum configuration options and repositories
copr                      Interact with Copr repositories.
debug-dump                dump information about installed rpm packages to file
debug-restore             restore packages recorded in debug-dump file
debuginfo-install         install debuginfo packages
download                  Download package to current directory
needs-restarting          determine updated binaries that need restarting
playground                Interact with Playground repository.
repoclosure               Display a list of unresolved dependencies for repositories
repodiff                  List differences between two sets of repositories
repograph                 Output a full package dependency graph in dot format
repomanage                Manage a directory of rpm packages
reposync                  download all packages from remote repo

General YUM options:
  -c [config file], --config [config file]
                        config file location
  -q, --quiet           quiet operation
  -v, --verbose         verbose operation
  --version             show YUM version and exit
  --installroot [path]  set install root
  --nodocs              do not install documentations
  --noplugins           disable all plugins
  --enableplugin [plugin]
                        enable plugins by name
  --disableplugin [plugin]
                        disable plugins by name
  --releasever RELEASEVER
                        override the value of $releasever in config and repo
                        files
  --setopt SETOPTS      set arbitrary config and repo options
  --skip-broken         resolve depsolve problems by skipping packages
  -h, --help, --help-cmd
                        show command help
  --allowerasing        allow erasing of installed packages to resolve
                        dependencies
  -b, --best            try the best available package versions in
                        transactions.
  --nobest              do not limit the transaction to the best candidate
  -C, --cacheonly       run entirely from system cache, don't update cache
  -R [minutes], --randomwait [minutes]
                        maximum command wait time
  -d [debug level], --debuglevel [debug level]
                        debugging output level
  --debugsolver         dumps detailed solving results into files
  --showduplicates      show duplicates, in repos, in list/search commands
  -e ERRORLEVEL, --errorlevel ERRORLEVEL
                        error output level
  --obsoletes           enables yum's obsoletes processing logic for upgrade
                        or display capabilities that the package obsoletes for
                        info, list and repoquery
  --rpmverbosity [debug level name]
                        debugging output level for rpm
  -y, --assumeyes       automatically answer yes for all questions
  --assumeno            automatically answer no for all questions
  --enablerepo [repo]   Enable additional repositories. List option. Supports
                        globs, can be specified multiple times.
  --disablerepo [repo]  Disable repositories. List option. Supports globs, can
                        be specified multiple times.
  --repo [repo], --repoid [repo]
                        enable just specific repositories by an id or a glob,
                        can be specified multiple times
  --enable              enable repos with config-manager command
                        (automatically saves)
  --disable             disable repos with config-manager command
                        (automatically saves)
  -x [package], --exclude [package], --excludepkgs [package]
                        exclude packages by name or glob
  --disableexcludes [repo], --disableexcludepkgs [repo]
                        disable excludepkgs
  --repofrompath [repo,path]
                        label and path to an additional repository to use
                        (same path as in a baseurl), can be specified multiple
                        times.
  --noautoremove        disable removal of dependencies that are no longer
                        used
  --nogpgcheck          disable gpg signature checking (if RPM policy allows)
  --color COLOR         control whether color is used
  --refresh             set metadata as expired before running the command
  -4                    resolve to IPv4 addresses only
  -6                    resolve to IPv6 addresses only
  --destdir DESTDIR, --downloaddir DESTDIR
                        set directory to copy packages to
  --downloadonly        only download packages
  --comment COMMENT     add a comment to transaction
  --bugfix              Include bugfix relevant packages, in updates
  --enhancement         Include enhancement relevant packages, in updates
  --newpackage          Include newpackage relevant packages, in updates
  --security            Include security relevant packages, in updates
  --advisory ADVISORY, --advisories ADVISORY
                        Include packages needed to fix the given advisory, in
                        updates
  --bz BUGZILLA, --bzs BUGZILLA
                        Include packages needed to fix the given BZ, in
                        updates
  --cve CVES, --cves CVES
                        Include packages needed to fix the given CVE, in
                        updates
  --sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}
                        Include security relevant packages matching the
                        severity, in updates
  --forcearch ARCH      Force the use of an architecture

8. dnf --help

$ dnf --help

usage: dnf [options] COMMAND

List of Main Commands:

alias                     List or create command aliases
autoremove                remove all unneeded packages that were originally installed as dependencies
check                     check for problems in the packagedb
check-update              check for available package upgrades
clean                     remove cached data
deplist                   List package's dependencies and what packages provide them
distro-sync               synchronize installed packages to the latest available versions
downgrade                 Downgrade a package
group                     display, or use, the groups information
help                      display a helpful usage message
history                   display, or use, the transaction history
info                      display details about a package or group of packages
install                   install a package or packages on your system
list                      list a package or groups of packages
makecache                 generate the metadata cache
mark                      mark or unmark installed packages as installed by user.
module                    Interact with Modules.
provides                  find what package provides the given value
reinstall                 reinstall a package
remove                    remove a package or packages from your system
repolist                  display the configured software repositories
repoquery                 search for packages matching keyword
repository-packages       run commands on top of all packages in given repository
search                    search package details for the given string
shell                     run an interactive DNF shell
swap                      run an interactive DNF mod for remove and install one spec
updateinfo                display advisories about packages
upgrade                   upgrade a package or packages on your system
upgrade-minimal           upgrade, but only 'newest' package match which fixes a problem that affects your system

General DNF options:
  -c [config file], --config [config file]
                        config file location
  -q, --quiet           quiet operation
  -v, --verbose         verbose operation
  --version             show DNF version and exit
  --installroot [path]  set install root
  --nodocs              do not install documentations
  --noplugins           disable all plugins
  --enableplugin [plugin]
                        enable plugins by name
  --disableplugin [plugin]
                        disable plugins by name
  --releasever RELEASEVER
                        override the value of $releasever in config and repo
                        files
  --setopt SETOPTS      set arbitrary config and repo options
  --skip-broken         resolve depsolve problems by skipping packages
  -h, --help, --help-cmd
                        show command help
  --allowerasing        allow erasing of installed packages to resolve
                        dependencies
  -b, --best            try the best available package versions in
                        transactions.
  --nobest              do not limit the transaction to the best candidate
  -C, --cacheonly       run entirely from system cache, don't update cache
  -R [minutes], --randomwait [minutes]
                        maximum command wait time
  -d [debug level], --debuglevel [debug level]
                        debugging output level
  --debugsolver         dumps detailed solving results into files
  --showduplicates      show duplicates, in repos, in list/search commands
  -e ERRORLEVEL, --errorlevel ERRORLEVEL
                        error output level
  --obsoletes           enables dnf's obsoletes processing logic for upgrade
                        or display capabilities that the package obsoletes for
                        info, list and repoquery
  --rpmverbosity [debug level name]
                        debugging output level for rpm
  -y, --assumeyes       automatically answer yes for all questions
  --assumeno            automatically answer no for all questions
  --enablerepo [repo]   Enable additional repositories. List option. Supports
                        globs, can be specified multiple times.
  --disablerepo [repo]  Disable repositories. List option. Supports globs, can
                        be specified multiple times.
  --repo [repo], --repoid [repo]
                        enable just specific repositories by an id or a glob,
                        can be specified multiple times
  --enable              enable repos with config-manager command
                        (automatically saves)
  --disable             disable repos with config-manager command
                        (automatically saves)
  -x [package], --exclude [package], --excludepkgs [package]
                        exclude packages by name or glob
  --disableexcludes [repo], --disableexcludepkgs [repo]
                        disable excludepkgs
  --repofrompath [repo,path]
                        label and path to an additional repository to use
                        (same path as in a baseurl), can be specified multiple
                        times.
  --noautoremove        disable removal of dependencies that are no longer
                        used
  --nogpgcheck          disable gpg signature checking (if RPM policy allows)
  --color COLOR         control whether color is used
  --refresh             set metadata as expired before running the command
  -4                    resolve to IPv4 addresses only
  -6                    resolve to IPv6 addresses only
  --destdir DESTDIR, --downloaddir DESTDIR
                        set directory to copy packages to
  --downloadonly        only download packages
  --comment COMMENT     add a comment to transaction
  --bugfix              Include bugfix relevant packages, in updates
  --enhancement         Include enhancement relevant packages, in updates
  --newpackage          Include newpackage relevant packages, in updates
  --security            Include security relevant packages, in updates
  --advisory ADVISORY, --advisories ADVISORY
                        Include packages needed to fix the given advisory, in
                        updates
  --bz BUGZILLA, --bzs BUGZILLA
                        Include packages needed to fix the given BZ, in
                        updates
  --cve CVES, --cves CVES
                        Include packages needed to fix the given CVE, in
                        updates
  --sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}
                        Include security relevant packages matching the
                        severity, in updates
  --forcearch ARCH      Force the use of an architecture

9. rpm --help

$ rpm --help

Usage: rpm [OPTION...]

Query/Verify package selection options:
  -a, --all                          query/verify all packages
  -f, --file                         query/verify package(s) owning file
  -g, --group                        query/verify package(s) in group
  -p, --package                      query/verify a package file
      --pkgid                        query/verify package(s) with package identifier
      --hdrid                        query/verify package(s) with header identifier
      --triggeredby                  query the package(s) triggered by the package
      --whatconflicts                query/verify the package(s) which require a dependency
      --whatrequires                 query/verify the package(s) which require a dependency
      --whatobsoletes                query/verify the package(s) which obsolete a dependency
      --whatprovides                 query/verify the package(s) which provide a dependency
      --whatrecommends               query/verify the package(s) which recommends a dependency
      --whatsuggests                 query/verify the package(s) which suggests a dependency
      --whatsupplements              query/verify the package(s) which supplements a dependency
      --whatenhances                 query/verify the package(s) which enhances a dependency
      --nomanifest                   do not process non-package files as manifests

Query options (with -q or --query):
  -c, --configfiles                  list all configuration files
  -d, --docfiles                     list all documentation files
  -L, --licensefiles                 list all license files
  -A, --artifactfiles                list all artifact files
      --dump                         dump basic file information
  -l, --list                         list files in package
      --queryformat=QUERYFORMAT      use the following query format
  -s, --state                        display the states of the listed files

Verify options (with -V or --verify):
      --nofiledigest                 don't verify digest of files
      --nofiles                      don't verify files in package
      --nodeps                       don't verify package dependencies
      --noscript                     don't execute verify script(s)

Install/Upgrade/Erase options:
      --allfiles                     install all files, even configurations which might otherwise be skipped
      --allmatches                   remove all packages which match <package> (normally an error is generated if <package>
                                     specified multiple packages)
      --badreloc                     relocate files in non-relocatable package
  -e, --erase=<package>+             erase (uninstall) package
      --excludedocs                  do not install documentation
      --excludepath=<path>           skip files with leading component <path> 
      --force                        short hand for --replacepkgs --replacefiles
  -F, --freshen=<packagefile>+       upgrade package(s) if already installed
  -h, --hash                         print hash marks as package installs (good with -v)
      --ignorearch                   don't verify package architecture
      --ignoreos                     don't verify package operating system
      --ignoresize                   don't check disk space before installing
      --noverify                     short hand for --ignorepayload --ignoresignature
  -i, --install                      install package(s)
      --justdb                       update the database, but do not modify the filesystem
      --nodeps                       do not verify package dependencies
      --nofiledigest                 don't verify digest of files
      --nocontexts                   don't install file security contexts
      --nocaps                       don't install file capabilities
      --noorder                      do not reorder package installation to satisfy dependencies
      --noscripts                    do not execute package scriptlet(s)
      --notriggers                   do not execute any scriptlet(s) triggered by this package
      --oldpackage                   upgrade to an old version of the package (--force on upgrades does this automatically)
      --percent                      print percentages as package installs
      --prefix=<dir>                 relocate the package to <dir>, if relocatable
      --relocate=<old>=<new>         relocate files from path <old> to <new>
      --replacefiles                 ignore file conflicts between packages
      --replacepkgs                  reinstall if the package is already present
      --test                         don't install, but tell if it would work or not
  -U, --upgrade=<packagefile>+       upgrade package(s)
      --reinstall=<packagefile>+     reinstall package(s)

Common options for all rpm modes and executables:
  -D, --define='MACRO EXPR'          define MACRO with value EXPR
      --undefine=MACRO               undefine MACRO
  -E, --eval='EXPR'                  print macro expansion of EXPR
      --target=CPU-VENDOR-OS         Specify target platform
      --macros=<FILE:...>            read <FILE:...> instead of default file(s)
      --noplugins                    don't enable any plugins
      --nodigest                     don't verify package digest(s)
      --nosignature                  don't verify package signature(s)
      --rcfile=<FILE:...>            read <FILE:...> instead of default file(s)
  -r, --root=ROOT                    use ROOT as top level directory (default: "/")
      --dbpath=DIRECTORY             use database in DIRECTORY
      --querytags                    display known query tags
      --showrc                       display final rpmrc and macro configuration
      --quiet                        provide less detailed output
  -v, --verbose                      provide more detailed output
      --version                      print the version of rpm being used

Options implemented via popt alias/exec:
      --scripts                      list install/erase scriptlets from package(s)
      --setperms                     set permissions of files in a package
      --setugids                     set user/group ownership of files in a package
      --setcaps                      set capabilities of files in a package
      --restore                      restore file/directory permissions
      --conflicts                    list capabilities this package conflicts with
      --obsoletes                    list other packages removed by installing this package
      --provides                     list capabilities that this package provides
      --requires                     list capabilities required by package(s)
      --recommends                   list capabilities recommended by package(s)
      --suggests                     list capabilities suggested by package(s)
      --supplements                  list capabilities supplemented by package(s)
      --enhances                     list capabilities enhanced by package(s)
      --info                         list descriptive information from package(s)
      --changelog                    list change logs for this package
      --changes                      list changes for this package with full time stamps
      --xml                          list metadata in xml
      --triggers                     list trigger scriptlets from package(s)
      --filetriggers                 list filetrigger scriptlets from package(s)
      --last                         list package(s) by install time, most recent first
      --dupes                        list duplicated packages
      --filesbypkg                   list all files from each package
      --fileclass                    list file names with their classes
      --filecolor                    list file names with their colors
      --fileprovide                  list file names with their provides
      --filerequire                  list file names with requires
      --filecaps                     list file names with their POSIX1.e capabilities

Help options:
  -?, --help                         Show this help message
      --usage                        Display brief usage message

Copyright © 2002-2019 某某自媒体运营 版权所有