目录
一、dnf,yum和rpm的区别和相同
相同之处:
它们都用于安装、升级、删除和查询软件包。
它们都使用RPM(Red Hat Package Manager)软件包格式。
区别:
dnf和yum是高级包管理工具,它们提供了更多的功能和便利性,而rpm是低级包管理工具。
dnf是Fedora系统中的默认包管理器,而yum是旧版本的Fedora和CentOS系统中的默认包管理器。
dnf和yum支持自动解决软件包依赖关系,可以自动下载和安装依赖的软件包,而rpm需要手动解决依赖关系。
dnf和yum可以从软件仓库中获取软件包,而rpm只能安装本地的软件包文件。
dnf和yum可以使用插件来扩展功能,而rpm没有这个功能。
总结:
dnf和yum是高级包管理工具,提供了更多的功能和便利性,可以自动解决软件包依赖关系,并且可以从软件仓库中获取软件包。而rpm是低级包管理工具,需要手动解决依赖关系,并且只能安装本地的软件包文件。
[root@xxx ~]# which yum
/usr/bin/yum
[root@xxx ~]# ll /usr/bin/yum
lrwxrwxrwx. 1 root root 5 Apr 14 13:20 /usr/bin/yum -> dnf-3
[root@xxx ~]# which dnf
/usr/bin/dnf
[root@xxx ~]# ll /usr/bin/dnf
lrwxrwxrwx. 1 root root 5 Apr 14 13:20 /usr/bin/dnf -> dnf-3
[root@xxx ~]# which dnf-3
/usr/bin/dnf-3
[root@xxx ~]# ll /usr/bin/dnf-3
-rwxr-xr-x. 1 root root 2094 Apr 14 13:20 /usr/bin/dnf-3
[root@xxx ~]#
yum 是dnf命令的软链接
二、yum常用命令
yum install <package>:安装指定的软件包。
yum remove <package>:卸载指定的软件包。(或者yum erase)
yum update:更新所有已安装的软件包。
yum upgrade:升级所有已安装的软件包,包括依赖关系。
yum search <keyword>:搜索与关键字匹配的软件包。
yum info <package>:获取指定软件包的详细信息。
yum list:列出所有已安装的软件包。
yum clean all:清除yum缓存。
yum repolist:列出所有可用的软件源。
yum check-update:检查是否有可用的软件包更新。yum whatprovides : 查看某个东西是由什么提供的
yum makecache:是一个 YUM 命令,用于生成本地软件包仓库的缓存。它会下载和解析配置文件中配置的所有仓库的
repomd.xml
文件,并将元数据存储在本地缓存中。当你运行
yum makecache
命令时,YUM 会检查每个配置的仓库,并下载或更新repomd.xml
文件和相关的元数据文件。这些元数据文件包含了软件包的描述信息、依赖关系、版本号等。通过生成本地软件包仓库的缓存,yum makecache
命令可以提高后续的软件包操作的速度和效率。在执行安装、升级或检索软件包时,YUM 可以直接从本地缓存中获取所需的元数据,而不需要每次都从远程仓库下载。通常,在使用 YUM 进行软件包管理的时候,建议在每次修改仓库配置文件后或定期执行
yum makecache
命令来更新本地缓存,以获取最新的软件包信息。
2.1 yum list
yum list是列出所有可安装的软件包列表,包含已安装和未安装的。 yum list installed则显示已安装软件包列表。yum list available 是显示可用的软件包。
2.2 yum whatprovides
yum whatprovides
2.3 yum 只下载不安装
[root@xxx test2]# yum install --downloadonly --dest=./
Updating Subscription Management repositories.
^CKeyboardInterrupt: Terminated.
[root@xxx test2]# yum install httpd --downloadonly --dest=./
Updating Subscription Management repositories.
Last metadata expiration check: 16:37:34 ago on Thu 08 Aug 2024 16:06:36 CST.
Package httpd-2.4.57-11.el9_4.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@xxx test2]# yum reinstall httpd --downloadonly --dest=./
Updating Subscription Management repositories.
Last metadata expiration check: 16:37:48 ago on Thu 08 Aug 2024 16:06:36 CST.
Dependencies resolved.
======================================================================================
Package Architecture Version Repository Size
======================================================================================
Reinstalling:
httpd x86_64 2.4.57-11.el9_4 base 45 k
Transaction Summary
======================================================================================
Total download size: 45 k
Installed size: 59 k
YUM will only download packages for the transaction.
Is this ok [y/N]: y
Downloading Packages:
httpd-2.4.57-11.el9_4.x86_64.rpm 92 kB/s | 45 kB 00:00
--------------------------------------------------------------------------------------
Total 91 kB/s | 45 kB 00:00
Complete!
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
[root@xxx test2]# ll
total 64
-rw-r--r--. 1 root root 16384 Aug 5 14:04 1.txt
-rw-r--r--. 1 root root 45859 Aug 9 08:44 httpd-2.4.57-11.el9_4.x86_64.rpm
2.4 yum groupinstall "Server with GUI"
这个命令会安装名为 "Server with GUI" 的软件包组,通常包括一个图形用户界面(GUI)及与服务器相关的基本工具和应用程序。这个软件包组常用于将服务器系统配置为具有图形界面的桌面环境。
2.5 yum grouplist hidden
[root@xxx conf]# yum grouplist hidden
Updating Subscription Management repositories.
Last metadata expiration check: 17:09:12 ago on Thu 08 Aug 2024 16:06:36 CST.
Available Environment Groups:
Server
Minimal Install
Workstation
Virtualization Host
Custom Operating System
Installed Environment Groups:
Server with GUI
Installed Groups:
base-x
Container Management
Guest Desktop Agents
Internet Browser
Multimedia
VMware platform specific packages
Printing Client
Core
Fonts
GNOME
Hardware Monitoring Utilities
Hardware Support
Headless Management
Common NetworkManager submodules
Server product core
Standard
Available Groups:
Backup Client
Conflicts AppStream
Console Internet Tools
Debugging Tools
Desktop Debugging and Performance Tools
DNS Name Server
.NET Development
Emacs
FTP Server
GNOME Applications
Graphics Creation Tools
Guest Agents
Input Methods
Internet Applications
Java Development
Java Platform
Legacy X Window System Compatibility
Office Suite and Productivity
Image based rpm-ostree support
Platform Development
KVM platform specific packages
Hyper-v platform specific packages
Remote Desktop Clients
RPM Development Tools
TeX formatting system
Virtualization Client
Virtualization Hypervisor
Virtualization Platform
Virtualization Tools
Basic Web Server
Additional Development
Anaconda tools
Base
Conflicts BaseOS
Development Tools
Dial-up Networking Support
File and Storage Server
Graphical Administration Tools
Infiniband Support
Large Systems Performance
Legacy UNIX Compatibility
Mail Server
Mainframe Access
Network File System Client
Network Servers
Networking Tools
Performance Tools
Python Web
Remote Management for Linux
Scientific Support
Security Tools
Smart Card Support
Windows File Server
System Tools
Workstation product core
会列出所有隐藏的软件包组,包括那些通常不会显示在常规的 yum grouplist
输出中的组。这可以帮助系统管理员查看和管理系统中所有的软件包组,包括那些用于系统内部管理或特殊用途的组。
三、rpm 常用命令
以下是一些常用的rpm命令:
rpm -qa:列出所有已安装的软件包。
rpm -qi <package_name>:显示指定软件包的详细信息。
rpm -ql <package_name>:列出指定软件包安装的文件列表。
rpm -qf <file_path>:查找指定文件属于哪个软件包。
rpm -e <package_name>:卸载指定的软件包。
rpm -ivh <package_file.rpm>:安装指定的软件包。
rpm -Uvh <package_file.rpm>:升级已安装的软件包。
rpm -Va:验证所有已安装的软件包的完整性。
rpm -q --whatrequires <package_name>:查找依赖于指定软件包的其他软件包。
rpm -q --whatprovides <file_path>:查找提供指定文件的软件包。
rpm -qc 查看配置文件
rpm -qd 查看帮助文档
rpm --nodeps 忽略依赖性
这些命令可以帮助你管理和查询已安装的软件包。