服务器系统版本:
[JJB@zywxy ~]# cat /etc/redhat-release CentOS Linux release 8.5.2111
在处理服务器漏洞修复是时候,多数漏洞只需要升级软件即可。在使用yum升级/更新包的时候,yum提供了update和upgrade两个Command,他俩有啥区别呢?该用哪一个呢?
我们先看下yum的man手册:
YUM(8) DNF YUM(8) NAME yum - redirecting to DNF Command Reference SYNOPSIS dnf [options] <command> [<args>...] DESCRIPTION DNF is the next upcoming major version of YUM, a package manager for RPM-based Linux distributions. It roughly maintains CLI compatibility with YUM and defines a strict API for extensions and plugins.
可以看到centos8的yum命令已经指向DNF命令了,就是说DNF已经替代了yum。
man手册中找到两处信息:
Upgrade Command Command: upgrade Aliases: up Deprecated aliases: update, upgrade-to, update-to, localupdate dnf [options] upgrade Updates each package to the latest version that is both available and resolvable. dnf [options] upgrade <package-spec>... Updates each specified package to the latest available version. Updates dependencies as necessary. When versions are specified in the <package-spec>, update to these versions. dnf [options] upgrade @<spec>... Alias for the dnf module update command. If the main obsoletes configure option is true or the --obsoletes flag is present, dnf will include package obsoletes in its calculations. For more information see obsoletes. See also Configuration Files Replacement Policy.
--obsoletes This option has an effect on an install/update, it enables dnf's obsoletes processing logic. For more information see the obsoletes option. This option also displays capabilities that the package obsoletes when used together with the repoquery command. Configuration Option: obsoletes
可以看出yum升级与–obsoletes配置有关系,再去官方查看相关信息:
SEE ALSO · dnf.conf(5), DNF Configuration Reference · dnf-PLUGIN(8) for documentation on DNF plugins. · dnf.modularity(7), Modularity overview. · dnf-transaction-json(5), Stored Transaction JSON Format Specification. · DNF project homepage (https://github.com/rpm-software-management/dnf/) · How to report a bug (https://github.com/rpm-software-management/dnf/wiki/Bug-Reporting) · YUM project homepage (http://yum.baseurl.org/)
obsoletesbooleanThis option only has affect during an install/update. It enables dnf’s obsoletes processing logic, which means it makes dnf check whether any dependencies of given package are no longer required and removes them. Useful when doing distribution level upgrades. Default is ‘true’.Command-line option: –obsoletes
Update and Upgrade Commands are the SameInvoking dnf update or dnf upgrade, in all their forms, has the same effect in DNF, with the latter being preferred. In YUM yum upgrade was exactly like yum –obsoletes update.
上面这两段官方说明,大概意思就是用dnf update 和 dnf upgrade是一样的,但是 yum upgrade 是和yum –obsoletes update一样(或者配置了obsoletes为true),obsoletes选项为true时会在安装/升级过程中将旧的package和依赖包删除,且DNF命令默认obsoletes为true。
所以,如果某些软件可能依赖旧的package,那么还是使用yum update package比较好。
至于DNF命令,可以在DNF 的主要配置文件/etc/dnf/dnf.conf中指定obsoletes为false:
[JJB@zywxy ~]# cat /etc/dnf/dnf.conf
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
obsoletes=0
666