300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Linux: 软件包管理工具 yum/dnf 命令(Fedora/CentOS/RedHat)

Linux: 软件包管理工具 yum/dnf 命令(Fedora/CentOS/RedHat)

时间:2021-01-27 04:36:57

相关推荐

Linux: 软件包管理工具 yum/dnf 命令(Fedora/CentOS/RedHat)

本文链接: https://xiets./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-3lrwxrwxrwx 1 root root 5 Mar 2 15:57 yum -> dnf-3

相关网站:

Yum Commands Wiki: /wiki/YumCommands.htmlDNF 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

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

$ yum alias --help...

7. yum --help

$ yum --helpusage: yum [options] COMMANDList of Main Commands:alias List or create command aliasesautoremoveremove all unneeded packages that were originally installed as dependenciescheck check for problems in the packagedbcheck-update check for available package upgradesclean remove cached datadeplist List package's dependencies and what packages provide themdistro-syncsynchronize installed packages to the latest available versionsdowngrade Downgrade a packagegroup display, or use, the groups informationhelp display a helpful usage messagehistory display, or use, the transaction historyinfo display details about a package or group of packagesinstall install a package or packages on your systemlist list a package or groups of packagesmakecache generate the metadata cachemark mark or unmark installed packages as installed by user.moduleInteract with Modules.provides find what package provides the given valuereinstall reinstall a packageremoveremove a package or packages from your systemrepolist display the configured software repositoriesrepoquery search for packages matching keywordrepository-packages run commands on top of all packages in given repositorysearchsearch package details for the given stringshell run an interactive YUM shellswap run an interactive YUM mod for remove and install one specupdateinfodisplay advisories about packagesupgrade upgrade a package or packages on your systemupgrade-minimal upgrade, but only 'newest' package match which fixes a problem that affects your systemList of Plugin Commands:builddep Install build dependencies for package or spec filechangelog Show changelog data of packagesconfig-manager manage yum configuration options and repositoriescopr Interact with Copr repositories.debug-dumpdump information about installed rpm packages to filedebug-restore restore packages recorded in debug-dump filedebuginfo-install install debuginfo packagesdownload Download package to current directoryneeds-restartingdetermine updated binaries that need restartingplaygroundInteract with Playground repository.repoclosureDisplay a list of unresolved dependencies for repositoriesrepodiff List differences between two sets of repositoriesrepograph Output a full package dependency graph in dot formatrepomanageManage a directory of rpm packagesreposync download all packages from remote repoGeneral 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 RELEASEVERoverride the value of $releasever in config and repofiles--setopt SETOPTSset arbitrary config and repo options--skip-broken resolve depsolve problems by skipping packages-h, --help, --help-cmdshow command help--allowerasing allow erasing of installed packages to resolvedependencies-b, --best try the best available package versions intransactions.--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--showduplicatesshow duplicates, in repos, in list/search commands-e ERRORLEVEL, --errorlevel ERRORLEVELerror output level--obsoletes enables yum's obsoletes processing logic for upgradeor display capabilities that the package obsoletes forinfo, 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. Supportsglobs, can be specified multiple times.--disablerepo [repo] Disable repositories. List option. Supports globs, canbe 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 multipletimes.--noautoremove disable removal of dependencies that are no longerused--nogpgcheckdisable gpg signature checking (if RPM policy allows)--color COLOR control whether color is used--refresh set metadata as expired before running the command-4resolve to IPv4 addresses only-6resolve to IPv6 addresses only--destdir DESTDIR, --downloaddir DESTDIRset directory to copy packages to--downloadonly only download packages--comment COMMENTadd a comment to transaction--bugfix Include bugfix relevant packages, in updates--enhancement Include enhancement relevant packages, in updates--newpackageInclude newpackage relevant packages, in updates--security Include security relevant packages, in updates--advisory ADVISORY, --advisories ADVISORYInclude packages needed to fix the given advisory, inupdates--bz BUGZILLA, --bzs BUGZILLAInclude packages needed to fix the given BZ, inupdates--cve CVES, --cves CVESInclude packages needed to fix the given CVE, inupdates--sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}Include security relevant packages matching theseverity, in updates--forcearch ARCHForce the use of an architecture

8. dnf --help

$ dnf --helpusage: dnf [options] COMMANDList of Main Commands:alias List or create command aliasesautoremoveremove all unneeded packages that were originally installed as dependenciescheck check for problems in the packagedbcheck-update check for available package upgradesclean remove cached datadeplist List package's dependencies and what packages provide themdistro-syncsynchronize installed packages to the latest available versionsdowngrade Downgrade a packagegroup display, or use, the groups informationhelp display a helpful usage messagehistory display, or use, the transaction historyinfo display details about a package or group of packagesinstall install a package or packages on your systemlist list a package or groups of packagesmakecache generate the metadata cachemark mark or unmark installed packages as installed by user.moduleInteract with Modules.provides find what package provides the given valuereinstall reinstall a packageremoveremove a package or packages from your systemrepolist display the configured software repositoriesrepoquery search for packages matching keywordrepository-packages run commands on top of all packages in given repositorysearchsearch package details for the given stringshell run an interactive DNF shellswap run an interactive DNF mod for remove and install one specupdateinfodisplay advisories about packagesupgrade upgrade a package or packages on your systemupgrade-minimal upgrade, but only 'newest' package match which fixes a problem that affects your systemGeneral 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 RELEASEVERoverride the value of $releasever in config and repofiles--setopt SETOPTSset arbitrary config and repo options--skip-broken resolve depsolve problems by skipping packages-h, --help, --help-cmdshow command help--allowerasing allow erasing of installed packages to resolvedependencies-b, --best try the best available package versions intransactions.--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--showduplicatesshow duplicates, in repos, in list/search commands-e ERRORLEVEL, --errorlevel ERRORLEVELerror output level--obsoletes enables dnf's obsoletes processing logic for upgradeor display capabilities that the package obsoletes forinfo, 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. Supportsglobs, can be specified multiple times.--disablerepo [repo] Disable repositories. List option. Supports globs, canbe 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 multipletimes.--noautoremove disable removal of dependencies that are no longerused--nogpgcheckdisable gpg signature checking (if RPM policy allows)--color COLOR control whether color is used--refresh set metadata as expired before running the command-4resolve to IPv4 addresses only-6resolve to IPv6 addresses only--destdir DESTDIR, --downloaddir DESTDIRset directory to copy packages to--downloadonly only download packages--comment COMMENTadd a comment to transaction--bugfix Include bugfix relevant packages, in updates--enhancement Include enhancement relevant packages, in updates--newpackageInclude newpackage relevant packages, in updates--security Include security relevant packages, in updates--advisory ADVISORY, --advisories ADVISORYInclude packages needed to fix the given advisory, inupdates--bz BUGZILLA, --bzs BUGZILLAInclude packages needed to fix the given BZ, inupdates--cve CVES, --cves CVESInclude packages needed to fix the given CVE, inupdates--sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}Include security relevant packages matching theseverity, in updates--forcearch ARCHForce the use of an architecture

9. rpm --help

$ rpm --helpUsage: rpm [OPTION...]Query/Verify package selection options:-a, --allquery/verify all packages-f, --filequery/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--whatconflictsquery/verify the package(s) which require a dependency--whatrequires query/verify the package(s) which require a dependency--whatobsoletesquery/verify the package(s) which obsolete a dependency--whatprovides query/verify the package(s) which provide a dependency--whatrecommendsquery/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 manifestsQuery options (with -q or --query):-c, --configfiles list all configuration files-d, --docfiles list all documentation files-L, --licensefiles list all license files-A, --artifactfileslist all artifact files--dumpdump basic file information-l, --listlist files in package--queryformat=QUERYFORMATuse the following query format-s, --state display the states of the listed filesVerify 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, --hashprint 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--noscriptsdo 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--testdon'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=MACROundefine 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)--nopluginsdon'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=ROOTuse ROOT as top level directory (default: "/")--dbpath=DIRECTORY use database in DIRECTORY--querytagsdisplay 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 usedOptions 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--conflictslist capabilities this package conflicts with--obsoleteslist 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)--infolist descriptive information from package(s)--changeloglist change logs for this package--changes list changes for this package with full time stamps--xmllist metadata in xml--triggers list trigger scriptlets from package(s)--filetriggers list filetrigger scriptlets from package(s)--lastlist package(s) by install time, most recent first--dupes list duplicated packages--filesbypkg list all files from each package--fileclasslist file names with their classes--filecolorlist 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 capabilitiesHelp options:-?, --helpShow this help message--usage Display brief usage message

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。