Linux程序包管理(二)
說完了程序包管理以及rpm的相關使用,接下來說說rpm的前端管理工具 YUM
YUM是什么?
   前面提到,yum是rpm程序包管理器的前端管理工具,那么yum到底是什么?又能做什么呢? YUM:yellow dog,Yellowdog Update Modifier,是一個在Fedora和RedHat以及CentOS中Shell前端軟件包管理器。基于RPM包管理,能夠從指定的服務器自動下載RPM包并且安裝,可以自動處理依賴性關系,并且一次安裝所有依賴的軟件包,無須繁瑣地一次次下載、安裝。
   yum的理念是使用一個中心倉庫(repository)管理一部分甚至一個distribution的應用程序相互關系,根據計算出來的軟件依賴關系進行相關的升級,安裝, 刪除等操作,減少了Linux用戶一直頭痛的dependencies的問題. 這一點上,yum和apt相同. apt原為debian的deb類型軟件管理所使用,但是現在也能用到RedHat 門下的rpm了.
  yum主要功能是更方便的添加/刪除/更新RPM包,自動解決包的依賴性問題,便于管理大量系統的更新問題.
  yum可以同時配置多個資源庫(Repository),簡潔的配置文件(/etc/yum.conf),自動解決增加或刪除rpm包時遇到的依賴性問題,保持與RPM數據庫的一致性.
YUM特點
-
可以同時配置多個資源庫
-
簡介的配置文件
-
自動解決或增加包的依賴關系
-
保持與RPM數據庫的一致性
配置YUM倉庫
前面說到,yum可以配置多個資源庫(Repository),這里我們根據yum的幾個配置文件來分別說明: [root@Daniel ~]# cd /etc/yum.repos.d/ [root@Daniel yum.repos.d]# ls CentOS-Base.repo.bak CentOS-Debuginfo.repo CentOS-Local.repo CentOS-Sources.repo dstat-0.7.2-1.el5.rfx.noarch.rpm CentOS-CR.repoCentOS-fasttrack.repo CentOS-Media.repo CentOS-Vault.repo [root@Daniel yum.repos.d]# cat CentOS-Sources.repo # CentOS-Sources.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base-source] name=CentOS-$releasever - Base Sources baseurl=http://vault.centos.org/centos/$releasever/os/Source/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates-source] name=CentOS-$releasever - Updates Sources baseurl=http://vault.centos.org/centos/$releasever/updates/Source/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras-source] name=CentOS-$releasever - Extras Sources baseurl=http://vault.centos.org/centos/$releasever/extras/Source/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus-source] name=CentOS-$releasever - Plus Sources baseurl=http://vault.centos.org/centos/$releasever/centosplus/Source/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
/etc/yum.repos.d/下文件查看
此配置文件為yum默認生效的文件,及執行yum安裝程序包時,系統是根據此文件中的說明去查找相關程序包安裝
[root@Daniel yum.repos.d]# cat CentOS-Base.repo.bak # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # #
CentOS官方鏡像源
[base] name=CentOS-$releasever - Base mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
發行版更新
#released updates [updates] name=CentOS-$releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
額外可用的包
#additional packages that may be useful [extras] name=CentOS-$releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
繼承已經存在包功能的包,默認不可用
#additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
我們截取其中相同部分做詳細說明:
倉庫指向的定義: [repositoryID] 表示“源標識”,可是指明是CentOS 7.x 或者Fedora EPEL源等 name=Some name for this repository 為倉庫指定名字 baseurl=url://path/to/repository/ 倉庫地址 enabled={1|0} 表示此倉庫是否可用,0表示不可用,1表示可用,默認為1 gpgcheck={1|0} 是否進行倉庫來源完整性和合法性檢測,1表示檢測,0表示不檢測, gpgkey=URL 指明密鑰文件 enablegroups={1|0} 是否允許在此倉庫基礎上使用 組 批量管理程序包,默認1允許。 failovermethod={roundrobin|priority} 默認為:roundrobin,意為隨機挑選; cost= 默認為1000
配置yum源示例:
首先將本地鏡像文件掛載好之后進入掛載目錄/etc/cdrom/下面查看,有一個Package目錄
[root@Daniel yum.repos.d]# cd /media/cdrom/ [root@Daniel cdrom]# ls CentOS_BuildTag EULA imagesLiveOSrepodata RPM-GPG-KEY-CentOS-Testing-7 EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL [root@Daniel cdrom]# pwd /media/cdrom
然后配置yum文件
[root@Daniel cdrom]# cd /etc/yum.repos.d/ [root@Daniel yum.repos.d]# cat CentOS-Local.repo [CentOS7.2] 源標識 為 CentOS7.2 name=CentOS 7.2 源名字 為 CentOS7.2 baseurl=file:///media/cdrom 源路徑 這里就是鏡像的掛載路徑 gpgcheck=0 是否檢查來源合法性和包完整性,不檢查 enabled=1 是否啟用此倉庫,默認為1 啟用,可以不用寫 上面為本地源 下面為網源 [Fedora-EPEL] name=Fedora EPEL for EL7 baseurl=http://mirrors.aliyun.com/epel/7/x86_64/ 此網源為阿里云的epel源 gpgcheck=0
清理yum緩存
[root@Daniel cdrom]# yum clean all 已加載插件:fastestmirror, langpacks 正在清理軟件源: CentOS7.2 Fedora-EPEL Cleaning up everything Cleaning up list of fastest mirrors [root@Daniel cdrom]# yum repolist 已加載插件:fastestmirror, langpacks CentOS7.2 | 3.6 kB 00:00:00 Fedora-EPEL | 4.3 kB 00:00:00 (1/5): CentOS7.2/group_gz | 155 kB 00:00:00 (2/5): CentOS7.2/primary_db | 5.3 MB 00:00:00 (3/5): Fedora-EPEL/group_gz | 170 kB 00:00:02 (4/5): Fedora-EPEL/updateinfo | 558 kB 00:00:03 (5/5): Fedora-EPEL/primary_db | 4.1 MB 00:00:04 Determining fastest mirrors 源標識源名稱 狀態 CentOS7.2 CentOS 7.2 9,007 Fedora-EPEL Fedora EPEL for EL710,082 repolist: 19,089 [root@Daniel cdrom]#
可以看到上述源標識名稱和狀態可用,表名yum源配置成功
YUM安裝
rpm -ivh yum-2.0.4-2noarch.rpm
YUM相關命令使用
yum [options] [command] [package ...] command is one of: * install package1 [package2] [...] * update [package1] [package2] [...] * update-to [package1] [package2] [...] * check-update * upgrade [package1] [package2] [...] * upgrade-to [package1] [package2] [...] * distribution-synchronization [package1] [package2] [...] * remove | erase package1 [package2] [...] * list [...] * info [...] * provides | whatprovides feature1 [feature2] [...] * clean [ packages | metadata | expire-cache | rpmdb | plugins | all ] * makecache * groupinstall group1 [group2] [...] * groupupdate group1 [group2] [...] * grouplist [hidden] [groupwildcard] [...] * groupremove group1 [group2] [...] * groupinfo group1 [...] * search string1 [string2] [...] * shell [filename] * resolvedep dep1 [dep2] [...] * localinstall rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use install) * localupdate rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use update) * reinstall package1 [package2] [...] * downgrade package1 [package2] [...] * deplist package1 [package2] [...] * repolist [all|enabled|disabled] * version [ all | installed | available | group-* | nogroups* | grouplist | groupinfo ] * history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats] * check * help [command]
顯示倉庫列表:
repolist [all|enabled|disabled] [root@Daniel ~]# yum repolist enabled 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 源標識源名稱 狀態 CentOS7.2 CentOS 7.2 9,007 Fedora-EPEL Fedora EPEL for EL710,082 repolist: 19,089 [root@Daniel ~]# yum repolist disabled 已加載插件:fastestmirror, langpacks 源標識 源名稱 C7.0.1406-base/x86_64CentOS-7.0.1406 - Base C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates C7.1.1503-base/x86_64CentOS-7.1.1503 - Base C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates base-debuginfo/x86_64CentOS-7 - Debuginfo base-source/7CentOS-7 - Base Sources c7-media CentOS-7 - Media centosplus-source/7 CentOS-7 - Plus Sources cr/7/x86_64 CentOS-7 - cr extras-source/7 CentOS-7 - Extras Sources fasttrack/7/x86_64 CentOS-7 - fasttrack updates-source/7 CentOS-7 - Updates Sources repolist: 0 [root@Daniel ~]# yum repolist all 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 源標識 源名稱 狀態 C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base 禁用 C7.0.1406-centosplus/x86_64CentOS-7.0.1406 - CentOSPlus 禁用 C7.0.1406-extras/x86_64CentOS-7.0.1406 - Extras 禁用 C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus 禁用 C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates 禁用 C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base 禁用 C7.1.1503-centosplus/x86_64CentOS-7.1.1503 - CentOSPlus 禁用 C7.1.1503-extras/x86_64CentOS-7.1.1503 - Extras 禁用 C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus 禁用 C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates 禁用 CentOS7.2 CentOS 7.2 啟用: 9,007 Fedora-EPELFedora EPEL for EL7 啟用: 10,082 base-debuginfo/x86_64 CentOS-7 - Debuginfo 禁用 base-source/7 CentOS-7 - Base Sources 禁用 c7-media CentOS-7 - Media 禁用 centosplus-source/7CentOS-7 - Plus Sources 禁用 cr/7/x86_64CentOS-7 - cr 禁用 extras-source/7CentOS-7 - Extras Sources 禁用 fasttrack/7/x86_64 CentOS-7 - fasttrack 禁用 updates-source/7 CentOS-7 - Updates Sources 禁用 repolist: 19,089 [root@Daniel ~]#
顯示程序包:
list # yum list [all | glob_exp1] [glob_exp2] [...] # yum list {available|installed|updates} [glob_exp1] [...]
安裝程序包:
install package1 [package2] [...] reinstall package1 [package2] [...] (重新安裝) [root@Daniel ~]# yum install unixODBC.x86_64 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 正在解決依賴關系 --> 正在檢查事務 ---> 軟件包 unixODBC.x86_64.0.2.3.1-11.el7 將被 安裝 --> 解決依賴關系完成 依賴關系解決 ============================================================================================================================================== Package 架構 版本 源 大小 ============================================================================================================================================== 正在安裝: unixODBC x86_64 2.3.1-11.el7 CentOS7.2 413 k 事務概要 ============================================================================================================================================== 安裝 1 軟件包 總下載量:413 k 安裝大?。?.2 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝: unixODBC-2.3.1-11.el7.x86_64 1/1 驗證中 : unixODBC-2.3.1-11.el7.x86_64 1/1 已安裝: unixODBC.x86_64 0:2.3.1-11.el7 完畢! [root@Daniel ~]#
升級程序包:
update [package1] [package2] [...] downgrade package1 [package2] [...] (降級)
檢查可用升級:
check-update [root@Daniel ~]# yum check-update 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile dstat.noarch 0.7.2-12.el7 CentOS7.2 htop.x86_64 2.0.1-1.el7 Fedora-EPEL libgpod.x86_640.8.3-7.el7 Fedora-EPEL [root@Daniel ~]#
卸載程序包:
remove | erase package1 [package2] [...] [root@Daniel ~]# yum remove unixODBC 已加載插件:fastestmirror, langpacks 正在解決依賴關系 --> 正在檢查事務 ---> 軟件包 unixODBC.x86_64.0.2.3.1-11.el7 將被 刪除 --> 正在處理依賴關系 libesoobS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libmimerS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libnn.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libodbccr.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libodbcdrvcfg1S.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libodbcdrvcfg2S.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libodbcminiS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libodbcnnS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libodbctxtS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 liboplodbcS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 liboraodbcS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libsapdbS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libtdsS.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 libtemplate.so.2()(64bit),它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在處理依賴關系 unixODBC(x86-64) = 2.3.1-11.el7,它被軟件包 unixODBC-devel-2.3.1-11.el7.x86_64 需要 --> 正在檢查事務 ---> 軟件包 unixODBC-devel.x86_64.0.2.3.1-11.el7 將被 刪除 --> 解決依賴關系完成 依賴關系解決 ============================================================================================================== Package 架構 版本源大小 ============================================================================================================== 正在刪除: unixODBC x86_64 2.3.1-11.el7@CentOS7.2 1.2 M 為依賴而移除: unixODBC-devel x86_64 2.3.1-11.el7installed186 k 事務概要 ============================================================================================================== 移除 1 軟件包 (+1 依賴軟件包) 安裝大?。?.4 M 是否繼續?[y/N]:y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction 正在刪除: unixODBC-devel-2.3.1-11.el7.x86_641/2 正在刪除: unixODBC-2.3.1-11.el7.x86_64 2/2 驗證中 : unixODBC-devel-2.3.1-11.el7.x86_641/2 驗證中 : unixODBC-2.3.1-11.el7.x86_64 2/2 刪除: unixODBC.x86_64 0:2.3.1-11.el7 作為依賴被刪除: unixODBC-devel.x86_64 0:2.3.1-11.el7 完畢!
查看程序包information:
info [...]
查看指定的特性(可以是某文件)是由哪個程序包所提供:
provides | whatprovides feature1 [feature2] [...] [root@Daniel ~]# yum provides /bin/ls 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile coreutils-8.22-15.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts 源:CentOS7.2 匹配來源: 文件名:/bin/ls coreutils-8.22-15.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts 源:@anaconda 匹配來源: 文件名:/bin/ls
清理本地緩存:
clean [ packages | metadata | expire-cache | rpmdb | plugins | all ] [root@Daniel ~]# yum clean all 已加載插件:fastestmirror, langpacks 正在清理軟件源: CentOS7.2 Fedora-EPEL Cleaning up everything Cleaning up list of fastest mirrors
構建緩存:
makecache
搜索:
search string1 [string2] [...] 以指定的關鍵字搜索程序包名及summary信息;
查看指定包所依賴的capabilities:
deplist package1 [package2] [...]
查看yum事務歷史:
history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
安裝及升級本地程序包:
* localinstall rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use install) * localupdate rpmfile1 [rpmfile2] [...] (maintained for legacy reasons only - use update)
包組管理的相關命令:
* groupinstall group1 [group2] [...] * groupupdate group1 [group2] [...] * grouplist [hidden] [groupwildcard] [...] * groupremove group1 [group2] [...] * groupinfo group1 [...]
yum的命令行選項:
--nogpgcheck:禁止進行gpg check; -y: 自動回答為“yes”; -q:靜默模式; --disablerepo=repoidglob:臨時禁用此處指定的repo; --enablerepo=repoidglob:臨時啟用此處指定的repo; --noplugins:禁用所有插件;
原創文章,作者:Daniel-W,如若轉載,請注明出處:http://www.www58058.com/17243
K8tIU7 http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com
Cob,ii&nlsp;Afrand to say that there was no influence from S.O.A.P. on my novel (though I have subsequently seen the movie). I do, though, much enjoy writing scenes that involve aircraft, as I spent 6 years in the Air Force, many years doing volunteer work with a group called The Commemorative Air Force (CAF) restoring a WW2 B-17 bomber, and have been around aircraft, in one capacity or another, for pretty much all my adult life. This likely shows in the writing where aircraft are involved in some way.234f