查看系統上已安裝的程序包有哪些可用更新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