目录
YUM是Red Hat的包管理器,基于RPM包管理,能够从指定的服务器自动下载RPM包并安装,可以自动处理依赖关系,并且一次安装所有依赖的软件包。本篇将对YUM的命令进行介绍。
1 YUM语法
yum [options] [command] [package ...]
2 常用示例
2.1 查看YUM资源库信息
1)方法一
[root@strong ~]# yum repoinfo
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repo-id : server
Repo-name : Red Hat Enterprise Linux 7.6
Repo-revision: 1539194633
Repo-updated : Thu Oct 11 02:03:53 2018
Repo-pkgs : 5,152
Repo-size : 3.4 G
Repo-baseurl : file:///mnt/
Repo-expire : 21,600 second(s) (last: Wed Sep 25 22:50:12 2019)
Filter : read-only:present
Repo-filename: /etc/yum.repos.d/server.repo
repolist: 5,152
2)方法二
[root@strong ~]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repo id repo name status
server Red Hat Enterprise Linux 7.6 5,152
repolist: 5,152
可以指定-v 查看更详细的信息。
2.2 查看可用的更新
[root@strong ~]# yum check-update
2.3 更新软件
1)更新所有软件
[root@strong ~]# yum update
2)更新某一个软件
[root@strong ~]# yum update sshd
3)仅更新到最新版本
[root@strong ~]# yum update --security sshd
4)仅更新到安全更新的版本
[root@strong ~]# yum update-minimal --security sshd
2.4 搜索软件包
[root@strong ~]# yum search sshd
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
=========================================================== Matched: sshd ============================================================
openssh-server.x86_64 : An open source SSH server daemon
2.5 列出软件包
1)列出所有软件包,包括已安装的和可用的
[root@strong ~]# yum list all
2)列出已安装的软件包
[root@strong ~]# yum list installed
3)列出可用的软件包
[root@strong ~]# yum list available |grep ssh
fence-agents-ilo-ssh.x86_64 4.2.1-11.el7 server
libssh2.i686 1.4.3-12.el7 server
openssh-askpass.x86_64 7.4p1-16.el7 server
openssh-keycat.x86_64 7.4p1-16.el7 server
2.6 查看软件包信息
[root@strong ~]# yum info openssh-server
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Installed Packages
Name : openssh-server
Arch : x86_64
Version : 7.4p1
Release : 16.el7
Size : 971 k
Repo : installed
From repo : anaconda
Summary : An open source SSH server daemon
URL : http://www.openssh.com/portable.html
License : BSD
Description : OpenSSH is a free version of SSH (Secure SHell), a program for logging
: into and executing commands on a remote machine. This package contains
: the secure shell daemon (sshd). The sshd daemon allows SSH clients to
: securely connect to your SSH server.
2.7 安装软件包
[root@strong ~]# yum install xclock
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
server | 4.3 kB 00:00:00
(1/2): server/group_gz | 146 kB 00:00:00
(2/2): server/primary_db | 4.2 MB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package xorg-x11-apps.x86_64 0:7.7-7.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
xorg-x11-apps x86_64 7.7-7.el7 server 307 k
Transaction Summary
======================================================================================================================================
Install 1 Package
Total download size: 307 k
Installed size: 772 k
Is this ok [y/d/N]:
输入y进行软件的安装;d表示只下载,不进行安装;N表示不安装软件。
2.8 卸载软件包
[root@strong ~]# yum remove xclock
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package xorg-x11-apps.x86_64 0:7.7-7.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Removing:
xorg-x11-apps x86_64 7.7-7.el7 @server 772 k
Transaction Summary
======================================================================================================================================
Remove 1 Package
Installed size: 772 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : xorg-x11-apps-7.7-7.el7.x86_64 1/1
Verifying : xorg-x11-apps-7.7-7.el7.x86_64 1/1
Removed:
xorg-x11-apps.x86_64 0:7.7-7.el7
Complete!
2.9 查看安装的历史信息
关于软件包安装的历史,存储在目录/var/lib/yum/history下面。
1)列出最近的20条记录
[root@strong ~]# yum history list
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
4 | root <root> | 2019-09-26 00:11 | Install | 1
3 | root <root> | 2019-09-26 00:09 | Erase | 1
2 | root <root> | 2019-09-26 00:08 | Install | 1
1 | System <unset> | 2019-09-20 21:02 | Install | 1559
history list
2)列出所有记录
[root@strong ~]# yum history list all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
4 | root <root> | 2019-09-26 00:11 | Install | 1
3 | root <root> | 2019-09-26 00:09 | Erase | 1
2 | root <root> | 2019-09-26 00:08 | Install | 1
1 | System <unset> | 2019-09-20 21:02 | Install | 1559
history list
3)列出指定ID的记录
[root@strong ~]# yum history list 2..3
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
3 | remove xclock | 2019-09-26 00:09 | Erase | 1
2 | install xclock | 2019-09-26 00:08 | Install | 1
history list
4)列出统计信息
[root@strong ~]# yum history stats
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
File : //var/lib/yum/history/history-2019-09-20.sqlite
Size : 1,896,448
Transactions: 4
Begin time : Fri Sep 20 21:02:04 2019
End time : Thu Sep 26 00:11:18 2019
Counts :
NEVRAC : 1,560
NEVRA : 1,560
NA : 1,560
NEVR : 1,560
rpm DB : 1,560
yum DB : 1,560
history stats
5)列出概要信息
[root@strong ~]# yum history summary
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Login user | Time | Action(s) | Altered
-------------------------------------------------------------------------------
root <root> | Last day | E, I | 3
System <unset> | Last week | Install | 1559
history summary
6)列出每个软件包的历史信息
[root@strong ~]# yum history package-list openssh-server.x86_64
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID | Action(s) | Package
-------------------------------------------------------------------------------
1 | Install | openssh-server-7.4p1-16.el7.x86_64
history package-list
2.10 回滚已安装的软件
利用yum history undo xxxx 可以回滚已安装的软件。
1)查看某个软件包的安装历史
[root@strong ~]# yum history package-list xorg-x11-apps
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID | Action(s) | Package
-------------------------------------------------------------------------------
4 | Install | xorg-x11-apps-7.7-7.el7.x86_64
3 | Erase | xorg-x11-apps-7.7-7.el7.x86_64
2 | Install | xorg-x11-apps-7.7-7.el7.x86_64
history package-list
2)回滚已安装的软件包
[root@strong ~]# yum history undo 4
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Undoing transaction 4, from Thu Sep 26 00:11:17 2019
Install xorg-x11-apps-7.7-7.el7.x86_64 @server
Resolving Dependencies
--> Running transaction check
---> Package xorg-x11-apps.x86_64 0:7.7-7.el7 will be erased
--> Finished Dependency Resolution
file:///mnt/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/repodata/repomd.xml"
Trying other mirror.
Dependencies Resolved
======================================================================================================================
Package Arch Version Repository Size
======================================================================================================================
Removing:
xorg-x11-apps x86_64 7.7-7.el7 @server 772 k
Transaction Summary
======================================================================================================================
Remove 1 Package
Installed size: 772 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : xorg-x11-apps-7.7-7.el7.x86_64 1/1
Verifying : xorg-x11-apps-7.7-7.el7.x86_64 1/1
Removed:
xorg-x11-apps.x86_64 0:7.7-7.el7
Complete!
2.11 重做已安装的软件
利用yum history redo xxxx 可以再安装的软件。
1)查看某个软件包的安装历史
[root@strong ~]# yum history package-list xorg-x11-apps
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID | Action(s) | Package
-------------------------------------------------------------------------------
5 | Erase | xorg-x11-apps-7.7-7.el7.x86_64
4 | Install | xorg-x11-apps-7.7-7.el7.x86_64
3 | Erase | xorg-x11-apps-7.7-7.el7.x86_64
2 | Install | xorg-x11-apps-7.7-7.el7.x86_64
history package-list
2)重新再安装软件
[root@strong ~]# yum history redo 5
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repeating transaction 5, from Tue Oct 1 14:33:48 2019
Erase xorg-x11-apps-7.7-7.el7.x86_64 @server
No package matched to remove: xorg-x11-apps-0:7.7-7.el7
history redo
[root@strong ~]# yum history redo 4
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repeating transaction 4, from Thu Sep 26 00:11:17 2019
Install xorg-x11-apps-7.7-7.el7.x86_64 @server
file:///mnt/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/repodata/repomd.xml"
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package xorg-x11-apps.x86_64 0:7.7-7.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================
Package Arch Version Repository Size
======================================================================================================================
Installing:
xorg-x11-apps x86_64 7.7-7.el7 server 307 k
Transaction Summary
=====================================================================================================================
Install 1 Package
Total download size: 307 k
Installed size: 772 k
Is this ok [y/d/N]: y