[toc] yum命令 檢查更新 查看系統上已安裝的程式包有哪些可用更新 GeoIP 包的名稱 x86_64 構建包的CPU架構 1.5.0 要安裝的更新包的版本 base 更新的程式包所在的存儲庫 更新程式包 我們可以一次更新一個、多個或所有程式包,更新時此程式包所有依賴的程式包也會進行更新。 更 ...
目錄
yum命令
檢查更新
查看系統上已安裝的程式包有哪些可用更新
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
...
- GeoIP - 包的名稱
- x86_64 - 構建包的CPU架構
- 1.5.0 - 要安裝的更新包的版本
- base - 更新的程式包所在的存儲庫
更新程式包
我們可以一次更新一個、多個或所有程式包,更新時此程式包所有依賴的程式包也會進行更新。
更新單個程式包
yum update package_name
示例:更新bash程式包
~]# 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所有的插件
-
bash.x86_64 - 表示所要安裝的更新包
-
yum預設情況下以交互方式運行
-
y 選項,表示同意安裝更新
-
d 選項,yum會立即下載程式包而不安裝它們。我們可以使用 yum localinstall 來安裝這些程式包,不過此命令已經廢棄,可直接使用 yum install 來安裝。
下載的程式包預設保存在為 /var/cache/yum/\(basearch/\)releasever/packages/
-
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 search返回匹配的程式包的名稱和摘要信息。
列出程式包
列出系統上所有已經安裝和可用的程式包
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倉庫名稱前會有一個 @CentOS7-base 標誌,如果沒有安裝,則沒有任何標誌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] [...]
列出yum倉庫
列出系統上每個已啟用倉庫的倉庫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
- 最右側輸出的狀態列 status 列出了相關倉庫的啟用和禁用狀態。
添加Yum倉庫
一般我們為方便管理都會在 /etc/yum.repos.d/目錄中添加文件尾碼為.repo的文件,而不是在/etc/yum.conf文件中添加。
互聯網上的Yum倉庫通常提供自己的.repo文件,我們只需要使用以下命令添加即可。
yum-config-manager --add-repo repository_url
- 其中repository_url是.repo文件的鏈接。
示例:給當前系統添加網易的CentOS源。
~]# yum-config-manager --add-repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
啟用Yum倉庫
yum-config-manager --enable repositoryID
- repositoryID是倉庫的唯一ID(使用 yum repolist all 列出可用的存儲庫ID)
啟用所有存儲庫
~]# yum-config-manager --enable \*
禁用Yum倉庫
yum-config-manager --disable repositoryID
- repositoryID是倉庫的唯一ID(使用 yum repolist all 列出可用的存儲庫ID)
禁用所有存儲庫
~] yum-config-manager --disable \*
添加Yum倉庫遇到的問題
[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