管理软件包
更新时间:2026-06-04
使用dnf可以进行查询、安装、删除软件包等操作。
搜索软件包
可以使用rpm包名称、缩写或者描述搜索需要的RPM包,使用命令如下:
Plain Text
1dnf search httpd(以httpd为例)
示例如下:
Plain Text
1# dnf search httpd
2====================== N/S matched: httpd ==================================
3httpd.aarch64 : Apache HTTP Server
4httpd-devel.aarch64 : Development interfaces for the Apache HTTP server
5httpd-manual.noarch : Documentation for the Apache HTTP server
6httpd-tools.aarch64 : Tools for use with the Apache HTTP Server
7libmicrohttpd.aarch64 : Lightweight library for embedding a webserver in applications
列出软件包清单
要列出系统中所有已安装的以及可用的RPM包信息,使用命令如下:
Plain Text
1dnf list all
要列出系统中特定的RPM包信息,使用命令如下:
Plain Text
1dnf list httpd(以httpd为例)
示例如下:
Plain Text
1# dnf list httpd
2Available Packages
3httpd.x86_64 2.4.51-21.bd2 Local
显示RPM包信息
要显示一个或者多个RPM包信息,使用命令如下:
Plain Text
1dnf info package_name...
例如搜索,命令如下:
Plain Text
1# dnf info httpd zip
2Installed Packages
3Name : httpd
4Version : 2.4.51
5Release : 21.bd2
6Architecture : x86_64
7Size : 4.6 M
8Source : httpd-2.4.51-21.bd2.src.rpm
9Repository : @System
10From repo : Baidu
11Summary : Apache HTTP Server
12URL : https://httpd.apache.org/
13License : ASL 2.0
14Description : Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant web server.
15
16Name : zip
17Version : 3.0
18Release : 30.bd2
19......
20Description :The zip program is a compression and file packaging utility. Zip has one
21 : compression method and can also store files without compression.
22 : Zip automatically chooses the better of the two for each file. Compression
23 : ratios of 2:1 to 3:1 are common for text files.
安装RPM包
要安装一个软件包及其所有未安装的依赖,请在root权限下执行如下命令:
Plain Text
1dnf install package_name
您也可以通过添加软件包名字同时安装多个软件包。请在root权限下执行如下命令:
Plain Text
1dnf install package_name package_name... --setopt=strict=0
示例如下:
Plain Text
1# dnf install httpd
说明:
- 安装RPM包过程中,若出现安装失败,可参考安装时出现软件包冲突、文件冲突或缺少软件包导致安装失败。
- 请勿安装install-scipts软件包,该包仅用于imageTailor工具裁剪ISO时使用,若在百度linux服务器操作系统系统上安装该软件包会导致系统无法启动。
- 在安装软件包时候,可以配置文件/etc/dnf/dnf.conf添加参数strict=False或运行dnf命令参数添加--setopt=strict=0禁用严格模式,在更改配置文件 /etc/dnf/dnf.conf之后,需要重新加载DNF的配置才能使更改生效。重新启动终端或运行 dnf clean all命令,可以确保新的配置文件读取到最新的设置。禁用严格模式也带来了一些风险和潜在的问题。安装不兼容的软件包可能导致系统崩溃、功能缺失或安全漏洞。因此,在禁用严格模式之前,建议了解所安装软件包的依赖关系,并确定风险和后果。
下载软件包
- 使用dnf下载软件包到本地,请在root权限下输入如下命令:
Plain Text
1dnf download package_name
- 如果需要同时下载未安装的依赖,则加上--resolve,使用命令如下:
Plain Text
1dnf download --resolve package_name
示例如下:
Plain Text
1# dnf download --resolve httpd
删除软件包
要卸载软件包以及相关的依赖软件包,请在root权限下执行如下命令:
Plain Text
1dnf remove package_name...
示例如下:
Plain Text
1# dnf remove httpd
评价此篇文章
