如何在 CentOS 和 RHEL 上检查并安装更新
对于系统管理员来说,安装软件包或内核本身的更新是一项强烈推荐且有益的任务;尤其是在安全更新或补丁方面。当发现安全漏洞时,必须更新受影响的软件,以减少整个系统的潜在安全风险。
如果您尚未将系统配置为自动安装安全补丁或更新,则需要手动执行此操作。在本文中,我们将向您展示如何在 CentOS 和 RHEL 发行版上检查和安装软件更新。
要检查已安装的软件包是否有可用更新,请使用 YUM 软件包管理器和 check-update 子命令;这可以帮助您查看所有存储库中的所有软件包更新(如果有)。
yum check-update
Loaded plugins: changelog, fastestmirror
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 22 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
mariadb | 2.9 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): epel/x86_64/updateinfo | 842 kB 00:00:15
(2/2): epel/x86_64/primary_db | 6.1 MB 00:00:00
Loading mirror speeds from cached hostfile
* base: mirrors.linode.com
* epel: mirror.vorboss.net
* extras: mirrors.linode.com
* updates: mirrors.linode.com
MariaDB-client.x86_64 10.1.28-1.el7.centos mariadb
MariaDB-common.x86_64 10.1.28-1.el7.centos mariadb
MariaDB-server.x86_64 10.1.28-1.el7.centos mariadb
MariaDB-shared.x86_64 10.1.28-1.el7.centos mariadb
NetworkManager.x86_64 1:1.8.0-11.el7_4 updates
NetworkManager-adsl.x86_64 1:1.8.0-11.el7_4 updates
....
要将单个软件包更新到最新可用版本,请运行以下命令。在此示例中,yum 将尝试更新 httpd 软件包。
yum update httpd
Loaded plugins: changelog, fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.linode.com
* epel: mirror.vorboss.net
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7.centos.4 will be updated
--> Processing Dependency: httpd = 2.4.6-45.el7.centos.4 for package: 1:mod_ssl-2.4.6-45.el7.centos.4.x86_64
---> Package httpd.x86_64 0:2.4.6-67.el7.centos.6 will be an update
--> Processing Dependency: httpd-tools = 2.4.6-67.el7.centos.6 for package: httpd-2.4.6-67.el7.centos.6.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-45.el7.centos.4 will be updated
---> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos.6 will be an update
---> Package mod_ssl.x86_64 1:2.4.6-45.el7.centos.4 will be updated
---> Package mod_ssl.x86_64 1:2.4.6-67.el7.centos.6 will be an update
....
要更新包组,下面的命令将更新您的开发工具(C 和 C++ 编译器以及相关实用程序)。
yum update "Development Tools"
Loaded plugins: changelog, fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.linode.com
* epel: mirror.vorboss.net
* extras: mirrors.linode.com
* updates: mirrors.linode.com
...
要将所有系统软件及其依赖项升级到最新版本,请使用以下命令:
yum update
Loaded plugins: changelog, fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.linode.com
* epel: mirror.vorboss.net
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:10.1.23-1.el7.centos will be updated
---> Package MariaDB-client.x86_64 0:10.1.28-1.el7.centos will be an update
---> Package MariaDB-common.x86_64 0:10.1.23-1.el7.centos will be updated
---> Package MariaDB-common.x86_64 0:10.1.28-1.el7.centos will be an update
---> Package MariaDB-server.x86_64 0:10.1.23-1.el7.centos will be updated
---> Package MariaDB-server.x86_64 0:10.1.28-1.el7.centos will be an update
---> Package MariaDB-shared.x86_64 0:10.1.23-1.el7.centos will be updated
---> Package MariaDB-shared.x86_64 0:10.1.28-1.el7.centos will be an update
---> Package NetworkManager.x86_64 1:1.4.0-19.el7_3 will be obsoleted
---> Package NetworkManager.x86_64 1:1.8.0-11.el7_4 will be obsoleting
....
就是这样!您可能想阅读以下相关文章。
- 如何在 CentOS 7 中安装或升级到最新内核版本
- 如何删除 CentOS、RHEL 和 Fedora 中旧的未使用的内核
- 如何在 Debian 和 Ubuntu 上自动安装安全更新
始终让您的 Linux 系统保持最新的安全性和常规软件包更新。您有任何问题要问,请使用下面的评论表。