欢迎来到电脑知识学习网,专业的电脑知识大全学习平台!

手机版

adds使用教程-(adds用法)

病毒安全 发布时间:2022-12-13 01:09:19
(adds用法)

提醒:本文为合集文章,后续会持续更新!

关注我,每日提升!

在正式介绍dnf之前,阿铭先给你看一个东西:

# ls -l /usr/bin/dnflrwxrwxrwx 1 root root 5 5月 10 21:28 /usr/bin/dnf -> dnf-3# ls -l /usr/bin/yumlrwxrwxrwx 1 root root 5 5月 10 21:28 /usr/bin/yum -> dnf-3

通过以上操作,你会发现在Rocky8里面,使用yum或者dnf,都是一样的,本质上都是dnf工具,所以在前面章节中阿铭使用yum命令就是在使用dnf命令。

10.2 dnf工具

Dnf工具最大的优势在于可以联网去下载所需要的RPM包,然后自动安装。如果要安装的RPM包有依赖关系,dnf工具会帮我们依次安装所有相关的RPM包。下面阿铭介绍一下常用的dnf命令。

10.2.1 列出所有可用的RPM包

使用yum list 命令,可以列出所有的RPM包资源,如下所示:

# dnf list |head -20上次元数据过期检查:1:45:34 前,执行于 2022年11月07日 星期一 21时26分29秒。已安装的软件包NetworkManager.x86_64 1:1.32.10-4.el8 @anacondaNetworkManager-config-server.noarch 1:1.32.10-4.el8 @anacondaNetworkManager-libnm.x86_64 1:1.32.10-4.el8 @anacondaNetworkManager-team.x86_64 1:1.32.10-4.el8 @anacondaNetworkManager-tui.x86_64 1:1.32.10-4.el8 @anacondaOpenIPMI-libs.x86_64 2.0.31-3.el8 @baseosacl.x86_64 电脑 2.2.53-1.el8.1 @anacondaadcli.x86_64 0.8.2-12.el8 @anacondaalsa-sof-firmware.noarch 1.8-1.el8 @anacondaannobin.x86_64 10.29-3.el8 @appstreamapr.x86_64 1.6.3-12.el8 @appstreamapr-devel.x86_64 1.6.3-12.el8 @appstreamapr-util.x86_64 1.6.1-6.el8.1 电脑 @appstreamapr-util-bdb.x86_64 1.6.1-6.el8.1 @appstreamapr-util-devel.x86_64 1.6.1-6.el8.1 @appstreamapr-util-openssl.x86_64 1.6.1-6.el8.1 @appstreamat.x86_64 3.1.20-11.el8 @anacondaattr.x86_64 2.4.48-3.el8 @anaconda

限于篇幅,阿铭只列举了18个RPM包的信息。如上例所示,最左侧是RPM包名,中间是版本信息,最右侧是安装信息。如果已安装,最右侧就显示@appstream或者@ anaconda,它们前面都会有一个@符号,这很好区分。如果未安装,则显示appStream、anaconda。如果你仔细看看,就会发现dnf list 命令会先列出已安装的包(installed 电脑 package),然后再列出可安装的包(available package)。

10.2.2 搜索RPM包

搜索RPM包的命令为dnf search [相关关键词],示例命令如下:

# dnf search vim上次元数据过期检查:1:49:06 前,执行于 2022年11月07日 星期一 21时26分29秒。======================================================================================================== 名称 和 概况 匹配:vim =========================================================================================================awesome-vim-colorschemes.noarch : Collection of color schemes for Neo/vim, merged for quick usebeakerlib-vim-syntax.noarch : Files for syntax highlighting BeakerLib tests in VIM editorboxes-vim.noarch : Vim plugin for boxesfluxbox-vim-syntax.noarch : Fluxbox syntax scripts for vimgeany-plugins-vimode.x86_64 : Vim-mode plugin for Geanyneovim.x86_64 : Vim-fork focused on extensibility and agilitynotmuch-vim.x86_64 : A Vim plugin for notmuchpython-neovim-doc.noarch : Documentation for python-neovimpython3-neovim.noarch : Python client to Neovimvim-X11.x86_64 : The VIM version of the vi editor for the X Window System - GVimvim-airline.noarch : Lean & mean status/tabline for vim that's light as airvim-ansible.noarch : Vim plugin for syntax highlighting ansible's common filetypesvim-common.x86_64 : The common files needed by any version of the VIM editorvim-devicons.noarch : Adds file type icons to Vim pluginsvim-editorconfig.noarch : EditorConfig Vim Pluginvim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancementsvim-filesystem.noarch : VIM filesystem layoutvim-fugitive-gitlab.noarch : GitLab support for vim-fugitive pluginvim-go.x86_64 : Go development plugin for Vimvim-gv.noarch : Git commit browser in Vimvim-jellybeans.noarch : A colorful, dark color scheme for Vimvim-minimal.x86_64 : A minimal version of the VIM editorvim-powerline.noarch : Powerline VIM plugin============================================================================================================ 名称 匹配:vim =============================================================================================================vim-fugitive.noarch : A Git wrapper so awesome, it should be illegalvim-gitgutter.noarch : Shows a git diff in the gutter and stages/undoes hunks and partial hunksvim-halibut.noarch : Syntax file for the halibut manual toolvim-nerdtree-git-plugin.noarch : Plugin of NERDTree showing git statusvim-pathogen.noarch : Manage your runtimepath============================================================================================================ 概况 匹配:vim =============================================================================================================kakoune.x86_64 : Code editor heavily inspired by Vimranger.noarch : A vim-like file manager

除了这样搜索方法外,阿铭还常用grep来过滤,从而找到相应的RPM包,如下所示:

# dnf list|grep vimvim-common.x86_64 2:8.0.1763-16.el8_5.13 @appstreamvim-enhanced.x86_64 2:8.0.1763-16.el8_5.13 @appstreamvim-filesystem.noarch 2:8.0.1763-16.el8_5.13 @appstreamvim-minimal.x86_64 2:8.0.1763-16.el8 @anacondavim-X11.x86_64 2:8.0.1763-19.el8_6.4 appstreamvim-common.x86_64 2:8.0.1763-19.el8_6.4 appstreamvim-enhanced.x86_64 2:8.0.1763-19.el8_6.4 appstreamvim-filesystem.noarch 2:8.0.1763-19.el8_6.4 appstreamvim-minimal.x86_64 2:8.0.1763-19.el8_6.4 baseos


10.2.3 安装RPM包

安装RPM包的命令为dnf install [-y] [RPM包名],如果不加-y选项,则会以与用户交互的方式安装。示例命令如下:

上次元数据过期检查:1:51:22 前,执行于 2022年11月07日 星期一 21时26分29秒。依赖关系解决。========================================================================================================================================================================================================================================= 软件包 架构 版本 仓库 大小=========================================================================================================================================================================================================================================安装: psmisc x86_64 23.1-5.el8 baseos 150 k事务概要=========================================================================================================================================================================================================================================安装 1 软件包总下载:150 k安装大小:483 k确定吗?[y/N]:y下载软件包:psmisc-23.1-5.el8.x86_64.rpm 196 kB/s | 150 kB 00:00-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------总计 195 kB/s | 150 kB 00:00运行事务检查事务检查成功。运行事务测试事务测试成功。运行事务 准备中 : 1/1 安装 : psmisc-23.1-5.el8.x86_64 1/1 运行脚本: psmisc-23.1-5.el8.x86_64 1/1 验证 : psmisc-23.1-5.el8.x86_64 1/1已安装: psmisc-23.1-5.el8.x86_64完毕!

在这个过程中,它首先会把需要安装的RPM包列出来,如果有依赖关系,也会把所有依赖的包列出来。然后询问用户是否需要安装,输入y则安装,输入n则不安装。但阿铭觉得这样太麻烦,所以会直接加上-y选项,这样就省略了询问用户是否安装的那一步。

10.2.4 卸载RPM包

卸载RPM包的命令为dnf remove [-y] [RPM包名],示例命令如下:

# dnf remove psmisc依赖关系解决。========================================================================================================================================================== 软件包 架构 版本 仓库 大小==========================================================================================================================================================移除: psmisc x86_64 23.1-5.el8 @baseos 483 k事务概要==========================================================================================================================================================移除 1 软件包将会释放空间:483 k确定吗?[y/N]:y运行事务检查事务检查成功。运行事务测试事务测试成功。运行事务 准备中 : 1/1 删除 : psmisc-23.1-5.el8.x86_64 1/1 运行脚本: psmisc-23.1-5.el8.x86_64 1/1 验证 : psmisc-23.1-5.el8.x86_64 1/1已移除: psmisc-23.1-5.el8.x86_64完毕!

卸载和安装一样,也可以直接加上-y选项,从而省略与用户交互的那一步。这里阿铭需要提醒一下,卸载某个RPM包时它会连带依赖的包一起卸载,所以一定要看清楚,不要连其他重要的RPM包也一起卸载了,以免影响正常的业务。建议使用dnf remove命令卸载包时,还是不要加-y选项了。

10.2.5 升级RPM包

升级RPM包的命令为dnf update [-y] [RPM包],示例命令如下:

# dnf update bash上次元数据过期检查:1:54:52 前,执行于 2022年11月07日 星期一 21时26分29秒。依赖关系解决。========================================================================================================================================================== 软件包 架构 版本 仓库 大小==========================================================================================================================================================升级: bash x86_64 4.4.20-4.el8_6 baseos 1.5 M事务概要==========================================================================================================================================================升级 1 软件包总下载:1.5 M确定吗?[y/N]:y下载软件包:bash-4.4.20-4.el8_6.x86_64.rpm 3.2 MB/s | 1.5 MB 00:00----------------------------------------------------------------------------------------------------------------------------------------------------------总计 3.1 MB/s | 1.5 MB 00:00运行事务检查事务检查成功。运行事务测试事务测试成功。运行事务 准备中 : 1/1 升级 : bash-4.4.20-4.el8_6.x86_64 1/2 运行脚本: bash-4.4.20-4.el8_6.x86_64 1/2 清理 : bash-4.4.20-2.el8.x86_64 2/2 运行脚本: bash-4.4.20-2.el8.x86_64 2/2 验证 : bash-4.4.20-4.el8_6.x86_64 1/2 验证 : bash-4.4.20-2.el8.x86_64 2/2已升级: bash-4.4.20-4.el8_6.x86_64完毕!

前面介绍了如何使用dnf工具搜索、安装、卸载以及升级RPM包,如果你掌握了这些技能,基本上就可以解决日常工作中遇到的与RPM包相关的问题了。当然,dnf工具还有好多其他好用的命令,阿铭不再一一举出,如果你感兴趣,可以使用man命令查阅帮助信息。除此之外,阿铭还会教你一些关于dnf工具的小应用。

10.2.6 搜索某个命令是由哪个RPM包安装的

阿铭经常遇到在系统里想要执行某个命令时发现命令不存在,这是因为系统里还没有安装过对应的包。此时就可以使用如下命令来搜一下:

# dnf provides vmstat上次元数据过期检查:1:59:44 前,执行于 2022年11月07日 星期一 21时26分29秒。procps-ng-3.3.15-6.el8.i686 : System and process monitoring utilities仓库 :baseos匹配来源:文件名 :/usr/bin/vmstatprocps-ng-3.3.15-6.el8.x86_64 : System and process monitoring utilities仓库 :@System匹配来源:文件名 :/usr/bin/vmstatprocps-ng-3.3.15-6.el8.x86_64 : System and process monitoring utilities仓库 :baseos匹配来源:文件名 :/usr/bin/vmstat

上例中,阿铭想搜一下vmstat这个命令是由哪个RPM包来安装的,使用了dnf provides就可以查看到vmstat命令是由procps-ng这个包安装来的。

10.2.7 更改dnf仓库为国内镜像站

上面章节里提到,dnf是通过从网络获取rpm包的,那么它是去哪里下载的RPM包呢?大家可以通过查看配置文件
/etc/yum.repos.d/Rocky-BaseOS.repo获得地址:

# cat /etc/yum.repos.d/Rocky-BaseOS.repo# Rocky-BaseOS.repo## The mirrorlist system uses the connecting IP address of the client and the# update status of each mirror to pick current mirrors that are geographically# close to the client. You should use this for Rocky updates unless you are# manually picking other mirrors.## If the mirrorlist does not work for you, you can try the commented out# baseurl line instead.[baseos]name=Rocky Linux $releasever - BaseOSmirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/BaseOS/$basearch/os/gpgcheck=1enabled=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

这里的mirrors.rockylinux.org为下载rpm的地址,该站点在国外,相对来说访问比较慢,我们可以将其更改为国内的镜像站点,比如阿里云的,具体方法如下。

(1) 将下载地址改为上海交大的镜像地址

sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.sjtug.sjtu.edu.cn/rocky|g' \ -i.bak /etc/yum.repos.d/Rocky-*.repo

(2) 刷新repos生成缓存,如下所示:

# dnf clean all# dnf makecache

然后就可以使用dnf命令安装你所需要的软件包了,比如我们可以安装一个tftp的RPM包,如下所示:

# dnf install –y tftp


10.2.8 下载RPM包

有时我们需要下载RPM包但不安装,而仅仅是复制给其他机器使用。其实,通过dnf安装rpm包时,它需要先下载这个RPM包,然后再去安装,所以使用yum工具完全可以做到只下载而不安装。

使用dnf download命令就可以直接下载rpm包了,它会将rpm包下载到当前目录下,当然如果不指定任何选项,它只下载指定的rpm包,并不会下载依赖的包,要想连同依赖的包一起下载,还需要指定--resolve选项,命令如下:

# mkdir /tmp/rmps# cd /tmp/rmps# dnf download --resolve vim-enhanced上次元数据过期检查:2:16:28 前,执行于 2022年11月07日 星期一 21时26分29秒。[SKIPPED] vim-enhanced-8.0.1763-19.el8_6.4.x86_64.rpm: Already downloaded(2/4): vim-filesystem-8.0.1763-19.el8_6.4.noarch.rpm 186 kB/s | 49 kB 00:00(3/4): gpm-libs-1.20.7-17.el8.x86_64.rpm 91 kB/s | 38 kB 00:00(4/4): vim-common-8.0.1763-19.el8_6.4.x86_64.rpm 4.1 MB/s | 6.3 MB 00:01


感谢阅读,关注我,持续为你输出高质量Linux技术文档!


电脑
责任编辑:电脑知识学习网

病毒安全