1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Linux系统之dnf包管理器的基本使用

Linux系统之dnf包管理器的基本使用

时间:2021-01-23 19:40:22

相关推荐

Linux系统之dnf包管理器的基本使用

Linux系统之dnf包管理器的基本使用

一、dnf工具介绍1. dnf工具简介2. dnf的功能 二、DNF的安装1. 检查本地操作系统版本2. 安装epel3. 检查本地yum仓库状态4. 安装dnf包 三、dnf的使用帮助1. 查看dnf版本2. 查看dnf命令的帮助信息3. dnf命令的选项解释 四、dnf命令的基本使用1. 查询dnf软件库2.查询系统的rpm包3. 软件包的安装与卸载4. 检查系统软件包的更新5. 升级所有系统软件包6. 查看dnf命令的执行历史7. 查看所有的软件包组8. 查询软件的详细信息 五、dnf命令的使用总结1. dnf命令的使用总结2. dnf与yum包管理器比较

一、dnf工具介绍

1. dnf工具简介

DNF(Dandified Yum)是Fedora Linux操作系统中的一个包管理器,它是基于Yum开发的。它的主要特点是快速、可靠、易用和优秀的用户体验。

2. dnf的功能

DNF提供了许多强大的功能和命令行工具,包括:

安装和升级软件包:可以使用dnf install和dnf update命令来安装和升级软件包。

查询和列出软件包:可以使用dnf search和dnf list命令来查询和列出软件包。

删除软件包:可以使用dnf remove命令来删除已安装的软件包。

清理系统:可以使用dnf clean命令来清理系统中的软件包缓存和元数据。

版本管理:可以使用dnf history命令来查看软件包操作历史记录,并进行回滚或重做操作。

软件包组管理:可以使用dnf group命令来安装、升级和删除软件包组。

存储库管理:可以使用dnf repolist命令来列出系统中的存储库,并使用dnf config命令来配置存储库。

二、DNF的安装

1. 检查本地操作系统版本

检查本地操作系统版本

[root@jeven ~]# cat /etc/system-releaseCentOS Linux release 7.6.1810 (Core)

2. 安装epel

配置epel,启动epel的yum仓库。

yum install epel-release -y

或者使用阿里云的epel源

wget -O /etc/yum.repos.d/epel.repo /repo/epel-7.repo

3. 检查本地yum仓库状态

检查本地yum仓库状态

[root@jeven ~]# yum repolist all |grep enable !base/7/x86_64 CentOS-7 - Base - enabled: 10,072epel/x86_64 Extra Packages for Enterprise Linux 7 - x8 enabled: 13,753!extras/7/x86_64CentOS-7 - Extras -enabled: 515!updates/7/x86_64CentOS-7 - Updates -enabled: 5,053

4. 安装dnf包

使用yum安装dnf包

yum install dnf -y

三、dnf的使用帮助

1. 查看dnf版本

查看dnf包管理器版本

[root@jeven ~]# dnf --version4.0.9Installed: dnf-0:4.0.9.2-2.el7_9.noarch at Mon 03 Jul 11:24:14 AM CSTBuilt : CentOS BuildSystem <> at Wed 07 Apr 03:52:38 PM CSTInstalled: rpm-0:4.11.3-48.el7_9.x86_64 at Sat 24 Jun 10:08:53 PM CSTBuilt : CentOS BuildSystem <> at Wed 24 Nov 04:33:39 PM CST

2. 查看dnf命令的帮助信息

查看DNF在Linux的help帮助信息

[root@jeven ~]# 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 systemOptional arguments:-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.-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]--disablerepo [repo]--repo [repo], --repoid [repo]enable just specific repositories by an id or a glob,can be specified multiple times--enable, --set-enabledenable repos with config-manager command(automatically saves)--disable, --set-disableddisable 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 additional repository, can bespecified multiple times.--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--bzs BUGZILLA Include packages needed to fix the given BZ, inupdates--cves CVES Include 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

3. dnf命令的选项解释

dnf命令的选项解释

DNF(Dandified Yum)是Fedora、CentOS、RHEL等Linux发行版上最新的包管理工具,下面是DNF工具常用选项的解释:1. `install`:安装一个或多个软件包2. `remove`:卸载一个或多个软件包3. `update`:更新现有的软件包4. `upgrade`:更新系统中所有软件包(包括依赖项)5. `info`:查询软件包详细信息6. `search`:搜索软件包7. `list`:列出系统中所有已安装的软件包8. `clean`:清除系统中的缓存9. `check-update`:检查系统中可用的更新10. `repository`:管理 YUM 仓库11. `module`:管理模块12. `group`:管理软件包组13. `config-manager`:管理 DNF 配置文件和库14. `version`:查看 DNF 版本信息

四、dnf命令的基本使用

1. 查询dnf软件库

查看系统中可用的DNF软件库

[root@jeven ~]# dnf repolistExtra Packages for Enterprise Linux 7 - x86_64 6.5 MB/s | 17 MB00:02 CentOS-7 - Base -7.0 MB/s | 10 MB00:01 CentOS-7 - Updates - 8.2 MB/s | 27 MB00:03 CentOS-7 - Extras - 978 kB/s | 332 kB00:00 repo id repo name statusbase CentOS-7 - Base -10,072epel Extra Packages for Enterprise Linux 7 - x86_64 13,753extrasCentOS-7 - Extras -515updates CentOS-7 - Updates - 5,053

查询系统中所有的 DNF软件库,包括可用于不可用的。

[root@jeven ~]# dnf repolist allLast metadata expiration check: 0:01:45 ago on Mon 03 Jul 07:32:09 PM CST.repo id repo name statusbase CentOS-7 - Base - enabled: 10,072centosplusCentOS-7 - Plus - disabledcontrib CentOS-7 - Contrib - disabledepel Extra Packages for Enterprise Linux 7 - x86_64 enabled: 13,753epel-debuginfo Extra Packages for Enterprise Linux 7 - x86_64 - Debug disabledepel-source Extra Packages for Enterprise Linux 7 - x86_64 - Source disabledextras CentOS-7 - Extras -enabled: 515updates CentOS-7 - Updates - enabled: 5,053

2.查询系统的rpm包

查询系统中所有的软件包,该命令用于列出用户系统上的所有来自软件库的可用软件包和所有已经安装在系统上的软件包。

dnf list

查询已经安装的rpm包

dnf list installed

查询可供安装的 RPM 包

dnf list available

搜索软件库中的某个软件包

[root@jeven ~]# dnf search fdiskLast metadata expiration check: 0:07:32 ago on Mon 03 Jul 07:32:09 PM CST.======================================================================= Summary Matched: fdisk ========================================================================gdisk.x86_64 : An fdisk-like partitioning tool for GPT disks

查询某个命令对应的软件名

dnf provides /bin/bash

3. 软件包的安装与卸载

安装软件包

dnf install tree -y

卸载软件包

dnf remove tree -y

更新软件包

dnf update tree -y

4. 检查系统软件包的更新

使用以下命令检查系统中所有软件包的更新

dnf check-update

5. 升级所有系统软件包

使用以下命令升级系统中所有有可用升级的软件包

dnf update 或 dnf upgrade

6. 查看dnf命令的执行历史

查看DNF命令的执行历史

[root@jeven ~]# dnf historyID| Command line | Date and time | Action(s)| Altered-------------------------------------------------------------------------------1 | install nginx -y | -07-03 19:47 | Install | 3

7. 查看所有的软件包组

查看所有的软件包组

dnf grouplist

安装开发包组

dnf groupinstall "Development Tools" -y

8. 查询软件的详细信息

查看某个软件的详细信息

[root@jeven ~]# dnf info treeLast metadata expiration check: 0:21:56 ago on Mon 03 Jul 07:32:09 PM CST.Installed PackagesName : treeVersion: 1.6.0Release: 10.el7Arch : x86_64Size : 87 kSource : tree-1.6.0-10.el7.src.rpmRepo : @SystemSummary: File system tree viewerURL: http://mama.indstate.edu/users/ice/tree/License: GPLv2+Description : The tree utility recursively displays the contents of directories in a: tree-like format. Tree is basically a UNIX port of the DOS tree: utility.

五、dnf命令的使用总结

1. dnf命令的使用总结

安装软件包:使用dnf install命令,后跟要安装的软件包的名称。例如,dnf install firefox安装Firefox浏览器。升级软件包:使用dnf upgrade命令升级所有已安装的软件包。dnf upgrade package-name升级单个软件包。搜索软件包:使用dnf search命令搜索要安装的软件包。例如,dnf search mysql搜索MySQL软件包。删除软件包:使用dnf remove命令删除已安装的软件包。例如,dnf remove firefox删除Firefox浏览器。列出已安装的软件包:使用dnf list installed命令列出所有已安装的软件包。列出可用的软件包:使用dnf list available命令列出所有可用的软件包。列出软件包的详细信息:使用dnf info package-name命令列出软件包的详细信息。清理缓存:使用dnf clean all命令清理DNF缓存。禁用或启用软件包仓库:使用dnf config-manager命令禁用或启用软件包仓库。例如,dnf config-manager --disable repository-name禁用软件包仓库。检查依赖关系:使用dnf check命令检查软件包之间的依赖关系。

2. dnf与yum包管理器比较

dnf相比于yum有以下几个优点:

性能更好:dnf使用了更先进的依赖关系解决算法,因此速度更快。

交互性更好:dnf提供更友好的命令行交互,支持自动补全、多个软件包同时安装、更好的错误信息提示等功能。

依赖关系处理更加精确:dnf可以非常准确地处理软件包之间的依赖关系,避免因为缺少依赖而导致安装失败的问题。

提供更多的包信息:dnf提供更多、更详细的软件包信息,包括依赖关系、提供的功能、安装的文件以及其他相关信息。

具有扩展性:dnf是基于插件架构设计的,可以方便地扩展新的功能。

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