Linux教程 Yum命令的使用

在這篇文章中,咱們將學習如何安裝,更新,刪除,查找安裝包,管理安裝包以及安裝包的倉庫在Linux系統使用RedHat開發的YUM(Yellowdog Updater Modified)工具。如下這些命令例子主要使用的是CentOS 6.3 練習總結出來的,你也可使用這些命令來對應的Linux環境上進行學習和練習。可是在使用這些命令時,你首先得熟悉Linux的命令,不然的話,有可能會操做失誤,對系統形成必定的影響和損壞。php

什麼是YUM?

YUM (Yellowdog Updater Modified)  是一個開源的命令行工具,以及基於圖形的軟件包管理工具, 用於基於 RPM (RedHat Package Manager) 的 Linux 系統。它容許用戶和系統管理員容易的安裝,升級,卸載或者查找軟件安裝包在Linux系統中,它被開發以及發佈經過 Seth Vidal 開源在GPL(General Public License) 下。這樣的話任何人均可如下載和訪問代碼進行開發以及修復Bugs。YUM使用大量的第三方倉庫經過依賴來自動安裝包。mysql

1,使用YUM安裝一個軟件

安裝一個軟件叫Firefox,僅僅運行如下命令,將會自動發現以及安裝全部要求的依賴。linux

# yum install firefox
Loaded plugins: fastestmirror
Dependencies Resolved
  ================================================================================================
Package   Arch Version Repository Size
================================================================================================
Updating:
firefox i686 10.0.6-1.el6.centos updates 20 M
Updating for dependencies:
xulrunner i686 10.0.6-1.el6.centos updates 12 M
Transaction Summary
================================================================================================
Install 0 Package(s)
Upgrade 2 Package(s)
Total download size: 32 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): firefox-10.0.6-1.el6.centos.i686.rpm | 20 MB 01:10
(2/2): xulrunner-10.0.6-1.el6.centos.i686.rpm | 12 MB 00:52
------------------------------------------------------------------------------------------------
Total 63 kB/s | 32 MB 02:04
Updated:
firefox.i686 0:10.0.6-1.el6.centos
Dependency Updated:
xulrunner.i686 0:10.0.6-1.el6.centos
Complete!

以上命令安裝任何包以前都會詢問是否要安裝,若是你想要自動安裝沒有任何提示,在命令里加一個參數-y 便可,例子以下:web

# yum -y install firefox

2,使用YUM刪除一個軟件

刪除一個軟件叫Firefox,僅僅運行如下命令,將會自動刪除該軟件的全部的依賴。sql

# yum remove firefox
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package firefox.i686 0:10.0.6-1.el6.centos set to be erased
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Removing:
firefox i686 10.0.6-1.el6.centos @updates 23 M
Transaction Summary
=================================================================================================
Remove 1 Package(s)
Reinstall 0 Package(s)
Downgrade 0 Package(s)
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : firefox-10.0.6-1.el6.centos.i686
1/1
Removed:
firefox.i686 0:10.0.6-1.el6.centos
Complete!

相同的是以上命令執行仍是會提醒你是否要卸載,若是不須要提示請加參數-y。shell

# yum -y remove firefox

3,使用YUM升級一個軟件

升級一個老版本的MySQL軟件,僅僅運行如下命令,將會自動發現以及安裝全部要求的依賴。centos

# yum update mysql
Loaded plugins: fastestmirror
Dependencies Resolved
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Updating:
vsftpd i386 2.0.5-24.el5_8.1 updates 144 k
Transaction Summary
=================================================================================================
Install 0 Package(s)
Upgrade 1 Package(s)
Total size: 144 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : vsftpd
1/2
Cleanup : vsftpd
2/2
Updated:
vsftpd.i386 0:2.0.5-24.el5_8.1
Complete!

4,使用YUM列出一個軟件的信息

使用list函數經過安裝包的名字查找軟件,例如查找openssh使用如下命令緩存

# yum list openssh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.neu.edu.cn
* epel: mirror.neu.edu.cn
* extras: mirror.neu.edu.cn
* rpmforge: mirror.nl.leaseweb.net
* updates: mirror.nus.edu.sg
Installed Packages openssh.i386 4.3p2-72.el5_6.3
installed
Available Packages 4.3p2-82.el5

若是要讓你的查詢更精確,使用那個安裝的對應的版本進行查詢。以下:less

# yum list openssh-4.3p2

5,使用YUM查詢匹配的軟件

若是你記不住軟件的名稱,可使用search來查找匹配該名稱的全部軟件。ssh

# yum search vsftpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.neu.edu.cn
* epel: mirror.neu.edu.cn
* extras: mirror.neu.edu.cn
* rpmforge: mirror.nl.leaseweb.net
* updates: ftp.iitm.ac.in
============================== Matched: vsftpd ========================
ccze.i386 : A robust log colorizer
pure-ftpd-selinux.i386 : SELinux support for Pure-FTPD
vsftpd.i386 : vsftpd - Very Secure Ftp Daemon

6,使用YUM獲取一個軟件的信息

安裝一個軟件前你想要知道該軟件的信息,僅僅運行如下命令,將會獲得該軟件的信息。

# yum info firefox
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.neu.edu.cn
* epel: mirror.neu.edu.cn
* extras: mirror.neu.edu.cn
* rpmforge: mirror.nl.leaseweb.net
* updates: ftp.iitm.ac.in
Available Packages
Name : firefox
Arch : i386
Version : 10.0.6
Release : 1.el5.centos
Size : 20 M
Repo : updates
Summary : Mozilla Firefox Web browser
URL : http://www.mozilla.org/projects/firefox/
License : MPLv1.1 or GPLv2+ or LGPLv2+
Description: Mozilla Firefox is an open-source web browser, designed for standards
: compliance, performance and portability.

7,使用YUM列出全部有效的安裝包

使用YUM列出全部有效的安裝包

# yum list | less

8,使用YUM列出全部已安裝的軟件包

使用如下命令則列出全部已安裝的軟件安裝包

# yum list installed | less

9,使用YUM查找對應的文件所屬的安裝包

使用provide命令查找對應文件所屬的軟件安裝包。就好比查找htppd.conf文件

# yum provides /etc/httpd/conf/httpd.conf
Loaded plugins: fastestmirror
httpd-2.2.3-63.el5.centos.i386 : Apache HTTP Server
Repo : base
Matched from:
Filename : /etc/httpd/conf/httpd.conf
httpd-2.2.3-63.el5.centos.1.i386 : Apache HTTP Server
Repo : updates
Matched from:
Filename : /etc/httpd/conf/httpd.conf
httpd-2.2.3-65.el5.centos.i386 : Apache HTTP Server
Repo : updates
Matched from:
Filename : /etc/httpd/conf/httpd.conf
httpd-2.2.3-53.el5.centos.1.i386 : Apache HTTP Server
Repo : installed
Matched from:
Other : Provides-match: /etc/httpd/conf/httpd.conf

10,使用YUM檢查可升級的軟件安裝包

使用如下命令檢查你的系統有多少軟件包可以升級

# yum check-update

11,使用YUM升級系統

使用如下命令將升級最新的系統軟件版本。

# yum update

12,使用YUM列出能安裝的一組包

在Linux系統中,許多安裝被綁定到到一個特定的組,從而不要單獨對每個安裝包進行安裝,你安裝特定組的包,將安裝全部相關聯的包。例如使用如下命令顯示有效的組。

# yum grouplist
Installed Groups:
Administration Tools
DNS Name Server
Dialup Networking Support
Editors
Engineering and Scientific
FTP Server
Graphics
Java Development
Legacy Network Server
Available Groups:
Authoring and Publishing
Base
Beagle
Cluster Storage
Clustering
Development Libraries
Development Tools
Eclipse
Educational Software
KDE (K Desktop Environment)
KDE Software Development

13,使用YUM安裝一組安裝包

安裝一組特定的軟件安裝包,咱們使用命令groupinstall,例如安裝軟件MySqlDatabase,只須要執行如下命令。

# yum groupinstall 'MySQL Database'
Dependencies Resolved
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Updating:
unixODBC i386 2.2.11-10.el5 base 290 k
Installing for dependencies:
unixODBC-libs i386 2.2.11-10.el5 base 551 k
Transaction Summary
=================================================================================================
Install 1 Package(s)
Upgrade 1 Package(s)
Total size: 841 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : unixODBC-libs 1/3
Updating : unixODBC 2/3
Cleanup : unixODBC 3/3
Dependency Installed:
unixODBC-libs.i386 0:2.2.11-10.el5
Updated:
unixODBC.i386 0:2.2.11-10.el5
Complete!

14,使用YUM升級一組軟件包

升級已經安裝的一組軟件包,使用如下命令便可安裝。

# yum groupupdate 'DNS Name Server'
Dependencies Resolved
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Updating:
bind i386 30:9.3.6-20.P1.el5_8.2 updates 981 k
bind-chroot i386 30:9.3.6-20.P1.el5_8.2 updates 47 k
Updating for dependencies:
bind-libs i386 30:9.3.6-20.P1.el5_8.2 updates 864 k
bind-utils i386 30:9.3.6-20.P1.el5_8.2 updates 174 k
Transaction Summary
=================================================================================================
Install 0 Package(s)
Upgrade 4 Package(s)
Total size: 2.0 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : bind-libs 1/8
Updating : bind 2/8
Updating : bind-chroot 3/8
Updating : bind-utils 4/8
Cleanup : bind 5/8
Cleanup : bind-chroot 6/8
Cleanup : bind-utils 7/8
Cleanup : bind-libs 8/8
Updated:
bind.i386 30:9.3.6-20.P1.el5_8.2 bind-chroot.i386 30:9.3.6-20.P1.el5_8.2
Dependency Updated:
bind-libs.i386 30:9.3.6-20.P1.el5_8.2 bind-utils.i386 30:9.3.6-20.P1.el5_8.2
Complete!

15,使用YUM刪除一組軟件安裝包

刪除系統中已存在的一組軟件包,使用如下命令

# yum groupremove 'DNS Name Server'
Dependencies Resolved
=================================================================================================
Package Arch Version Repository Size
=================================================================================================
Removing:
bind i386 30:9.3.6-20.P1.el5_8.2 installed 2.1 M
bind-chroot i386 30:9.3.6-20.P1.el5_8.2 installed 0.0
Transaction Summary
=================================================================================================
Remove 2 Package(s)
Reinstall 0 Package(s)
Downgrade 0 Package(s)
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : bind 1/2
warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave
Erasing : bind-chroot 2/2
Removed:
bind.i386 30:9.3.6-20.P1.el5_8.2 bind-chroot.i386 30:9.3.6-20.P1.el5_8.2
Complete!

 

16,列出可以使用的YUM倉庫

使用如下命令列出全部可以使用的倉庫的在你的系統。

# yum repolist
repo id repo name status
base CentOS-5 - Base enabled: 2,725
epel Extra Packages for Enterprise Linux 5 - i386 enabled: 5,783
extras CentOS-5 - Extras enabled: 282
mod-pagespeed mod-pagespeed enabled: 1
rpmforge RHEL 5 - RPMforge.net - dag enabled: 11,290
updates CentOS-5 - Updates enabled: 743
repolist: 20,824

17,列出全部可用以及不可用的YUM倉庫

使用如下命令列出全部可以使用的和不可以使用的倉庫的在你的系統。

# yum repolist all
repo id repo name status
C5.0-base CentOS-5.0 - Base disabled
C5.0-centosplus CentOS-5.0 - Plus disabled
C5.0-extras CentOS-5.0 - Extras disabled
base CentOS-5 - Base enabled: 2,725
epel Extra Packages for Enterprise Linux 5 - i386 enabled: 5,783
extras CentOS-5 - Extras enabled: 282
repolist: 20,824

 

18,安裝一個軟件包從特定的倉庫

從一個特定的可用的或者不可用的倉庫中安裝一個軟件安裝包,你應該使用–enablerepo 參數來指定倉庫,例如安裝phpmyadmin安裝包,你執行如下命令便可。

# yum --enablerepo=epel install phpmyadmin

Dependencies Resolved
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Installing:
phpMyAdmin noarch 3.5.1-1.el6 epel 4.2 M
Transaction Summary
=============================================================================================
Install 1 Package(s)
Total download size: 4.2 M
Installed size: 17 M
Is this ok [y/N]: y
Downloading Packages:
phpMyAdmin-3.5.1-1.el6.noarch.rpm | 4.2 MB 00:25
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : phpMyAdmin-3.5.1-1.el6.noarch 1/1
Verifying : phpMyAdmin-3.5.1-1.el6.noarch 1/1

Installed:
phpMyAdmin.noarch 0:3.5.1-1.el6
Complete!

18,使用YUM Shell 進行交互

YUM Shell可以執行多個命令的腳本。

# yum shell
Loaded plugins: fastestmirror
Setting up Yum Shell
> update httpd
Loading mirror speeds from cached hostfile
* base: mirrors.sin3.sg.voxel.net
* epel: ftp.riken.jp
* extras: mirrors.sin3.sg.voxel.net
* updates: mirrors.sin3.sg.voxel.net
Setting up Update Process
>

19,清除YUM緩存

默認狀況下YUM保持全部可用的安裝包的倉庫的數據在/var/cache/yum/ 目錄下的每個子目錄中,清除全部的可用的倉庫的緩存,你須要運行如下命令清除全部緩存而且確保沒有空間被佔用,通常狀況下,咱們是不建議清除的,由於咱們想保留緩存在系統中,方便安裝和查找。

# yum clean all

20,查看YUM的安裝歷史

列出全部過去YUM處理的操做以及YUM安裝的歷史記錄

# yum history

Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
10 | root | 2018-08-11 15:19 | Install | 3
9 | root | 2018-08-11 15:11 | Install | 1
8 | root | 2018-08-11 15:10 | Erase | 1 EE
7 | root | 2018-08-10 17:44 | Install | 1
6 | root | 2018-08-10 12:19 | Install | 2
5 | root | 2018-08-10 12:14 | Install | 3
4 | root | 2018-08-10 12:12 | I, U | 13 E<
3 | root | 2018-08-09 13:01 | Install | 1 >
2 | root | 2018-08-08 20:13 | I, U | 292 EE
1 | System | 2018-08-08 17:15 | Install | 560
history list

以上是全部練習概括的YUM命令,若是你有任何其它相關的YUM的命令,能夠在留言或者評論區留下你想要新增的YUM命令,後期更新到文章上,多謝你們的支持,寫的很差的地方請多多包含,也望能提出你寶貴的意見。

相關文章
相關標籤/搜索