查看系统上已安装的程序包有哪些可用更新html
yum check-update
~]# yum check-update Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile GeoIP.x86_64 1.5.0-14.el7 base NetworkManager.x86_64 1:1.18.4-3.el7 base NetworkManager-libnm.x86_64 1:1.18.4-3.el7 base NetworkManager-team.x86_64 1:1.18.4-3.el7 base NetworkManager-tui.x86_64 1:1.18.4-3.el7 base acl.x86_64 2.2.51-15.el7 base alsa-lib.x86_64 1.1.8-1.el7 base ...
咱们能够一次更新一个、多个或全部程序包,更新时此程序包全部依赖的程序包也会进行更新。node
更新单个程序包mysql
yum update package_name
示例:更新bash程序包web
~]# yum update bash Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package bash.x86_64 0:4.2.46-31.el7 will be updated ---> Package bash.x86_64 0:4.2.46-34.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ========================================================================================= Package Arch Version Repository Size ========================================================================================= Updating: bash x86_64 4.2.46-34.el7 base 1.0 M Transaction Summary ========================================================================================= Upgrade 1 Package Total download size: 1.0 M Is this ok [y/d/N]:
Loaded plugins - 显示Yum全部的插件sql
bash.x86_64 - 表示所要安装的更新包docker
yum默认状况下以交互方式运行shell
y 选项,表示赞成安装更新apache
d 选项,yum会当即下载程序包而不安装它们。咱们能够使用 yum localinstall 来安装这些程序包,不过此命令已经废弃,可直接使用 yum install 来安装。windows
下载的程序包默认保存在为 /var/cache/yum/\(basearch/\)releasever/packages/centos
N 取消安装更新
更新全部程序包及其依赖的程序包
yum update
更新与安全相关的包
若是程序包具备可用的安全更新,则只能将这些程序包更新为其最新版本。
yum update --security
yum search package_name
~]# yum search zsh Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile =================== N/S matched: zsh ========================== autojump-zsh.noarch : Autojump for zsh zsh-html.x86_64 : Zsh shell manual in html format zsh.x86_64 : Powerful interactive shell zsh-lovers.noarch : A collection of tips, tricks and examples for the Z shell Name and summary matches only, use "search all" for everything.
列出系统上全部已经安装和可用的程序包
yum list all
~]# yum list all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages GeoIP.x86_64 1.5.0-11.el7 @CentOS7-base NetworkManager.x86_64 1:1.10.2-13.el7 @CentOS7-base accountsservice.x86_64 0.6.45-7.el7 CentOS7-base accountsservice-devel.i686 0.6.45-7.el7 CentOS7-base ......
列出系统上已经安装的全部程序包,输出内容最右侧表示程序包所在的yum仓库。
yum list installed
~]# yum list installed Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages GeoIP.x86_64 1.5.0-11.el7 @CentOS7-base NetworkManager.x86_64 1:1.10.2-13.el7 @CentOS7-base
列出全部已启用存储库中的全部可用的程序包
yum list available
~]# yum list available Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Available Packages 0ad.x86_64 0.0.22-1.el7 fedora-epel-7 0ad-data.noarch 0.0.22-1.el7 fedora-epel-7 0install.x86_64 2.11-1.el7 fedora-epel-7
yum grouplist
[root@node1 ~]# yum groups list Loaded plugins: fastestmirror There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile Available Environment Groups: Minimal Install Compute Node Infrastructure Server File and Print Server Basic Web Server Virtualization Host Server with GUI GNOME Desktop KDE Plasma Workspaces Development and Creative Workstation Available Groups: Compatibility Libraries Console Internet Tools Development Tools Graphical Administration Tools Legacy UNIX Compatibility Scientific Support Security Tools Smart Card Support System Administration Tools System Management Done
列出全部程序包组的组ID
[root@node1 ~]# yum grouplist ids Loaded plugins: fastestmirror There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile Available Environment Groups: Minimal Install (minimal) Compute Node (compute-node-environment) Infrastructure Server (infrastructure-server-environment) File and Print Server (file-print-server-environment) Basic Web Server (web-server-environment) Virtualization Host (virtualization-host-environment) Server with GUI (graphical-server-environment) GNOME Desktop (gnome-desktop-environment) KDE Plasma Workspaces (kde-desktop-environment) Development and Creative Workstation (developer-workstation-environment) Available Groups: Compatibility Libraries (compat-libraries) Console Internet Tools (console-internet) Development Tools (development) Graphical Administration Tools (graphical-admin-tools) Legacy UNIX Compatibility (legacy-unix) Scientific Support (scientific) Security Tools (security-tools) Smart Card Support (smart-card) System Administration Tools (system-admin-tools) System Management (system-management) Done
列出全部的程序包的组ID及隐藏的ID
[root@node1 ~]# yum grouplist hidden ids
安装程序包组有四种方法
yum group install "group name" yum group install groupid yum install @group yum install @^group
示例:以Development Tools为例,显示四种安装方法
~]# yum group install "Development Tools" ~]# yum group install development ~]# yum install @"Development Tools" ~]# yum install @development
yum group remove "group name" yum group remove groupid yum remove @group yum remove @^group
示例:以Development Tools为例,显示四种卸载程序包组的方法
~]# yum group remove "Development Tools" ~]# yum group remove development ~]# yum remove @"Development Tools" ~]# yum remove @development
查看一个或多个程序包的信息
~]#yum info package_name1 [package_name2] [...]
示例:查看httpd程序包的信息。
~]# yum info httpd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : httpd Arch : x86_64 Version : 2.4.6 Release : 80.el7.centos Size : 9.4 M Repo : installed From repo : CentOS7-base Summary : Apache HTTP Server URL : http://httpd.apache.org/ License : ASL 2.0 Description : The Apache HTTP Server is a powerful, : efficient, and extensible web server.
安装程序包时 yum命令会自动解决依赖关系,将程序包及其全部未安装的依赖的程序包都安装。
安装单个程序包
~]# yum install package_name
安装多个程序包
安装多个程序包时,能够将多个程序包名以空格分隔来安装。
~]# yum install package_name1 [package_name2] [...]
默认安装程序包的最新版本,安装旧版本时须要指定版本号。
示例:同时安装多个程序包。
~]# yum install httpd mysql
当咱们只是知道要安装的二进制文件的名称,而不知道其程序包名称,则能够为 yum install 提供路径名称。
~]# yum install /usr/bin/passwd
这时yum会搜索包列表,检索哪一个包提供了/usr/bin/passwd,若是有的话就会提供咱们安装。
查看指定的文件是由哪一个程序包提供
yum provides “filename”
当咱们只是知道一个命令,如ls,但不肯定其到底安装在/bin目录仍是/sbin/目录中,以及ls命令是由哪一个程序包安装,咱们能够使用 yum provides 命令。
# yum provides "*bin/ls" Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile coreutils-8.22-21.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts Repo: CentOS7-base Matched from: Filename: /bin/ls Filename: /usr/bin/ls coreutils-8.22-21.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts Repo: @CentOS7-base Matched from: Filename: /bin/ls Filename: /usr/bin/ls
~]# yum reinstall httpd
要卸载特定程序包以及依赖于它的任何程序包
yum remove package_name...
示例:卸载httpd程序包
~]# yum remove httpd
卸载多个程序包
~]# yum remove package_name1 [package_name2] [...]
列出系统上每一个已启用仓库的仓库ID,名称和程序包数量。
~]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status CentOS7-base CentOS7-base 9,911 docker-ce-7 docker-ce-7 156 fedora-epel-7 fedora-epel-7 12,661
yum repolist 只显示状态为enabled的仓库信息。使用 yum repoinfo命令列出仓库的更多信息,不过此命令在CentOS6系统上不可用。
列出已经启用和禁用的仓库
yum repolist all
~]# yum repolist all Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base disabled CentOS7-base CentOS7-base enabled: 9,911 fedora-epel-7 fedora-epel-7 enabled: 12,661
通常咱们为方便管理都会在 /etc/yum.repos.d/目录中添加文件后缀为.repo的文件,而不是在/etc/yum.conf文件中添加。
互联网上的Yum仓库一般提供本身的.repo文件,咱们只须要使用如下命令添加便可。
yum-config-manager --add-repo repository_url
示例:给当前系统添加网易的CentOS源。
~]# yum-config-manager --add-repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum-config-manager --enable repositoryID
启用全部存储库
~]# yum-config-manager --enable \*
yum-config-manager --disable repositoryID
禁用全部存储库
~] yum-config-manager --disable \*
[root@node1 ~]# yum-config-manager --add-repo https://mirrors.163.com/.help/CentOS7-Base-163.repo Loaded plugins: fastestmirror adding repo from: https://mirrors.163.com/.help/CentOS7-Base-163.repo grabbing file https://mirrors.163.com/.help/CentOS7-Base-163.repo to /etc/yum.repos.d/CentOS7-Base-163.repo Could not fetch/save url https://mirrors.163.com/.help/CentOS7-Base-163.repo to file /etc/yum.repos.d/CentOS7-Base-163.repo: [Errno 14] curl#60 - "Peer's Certificate has expired."
出现问题的缘由是当前系统的时间与yum源的时间不一致致使。
解决办法:
[root@node1 ~]# yum -y install ntp [root@node1 ~]# ntpdate time.windows.com
列出全部与安全相关的更新
yum --security check-update
若是程序包具备可用的安全更新,则将这些程序包更新为最新版本
yum --security update
只安装最安全的安全更新,忽略全部可能包含不安全新功能的包
yum --security update-minimal