Yum 能從多個套件倉庫中解析相依關係,減少安裝時的依賴困擾。但在圖形介面下開「應用程式 → 新增/移除軟體」時,瀏覽清單卻是空的,如下圖:

第一步:建立目錄並把光盤內容全部複製進去。
[root@localhost ~]# mkdir /yum
[root@localhost ~]# cp -rvf /misc/cd/* /yum
第二步:備份 repodata。因為四個目錄下都有這個資料夾,全部都要備份。
[root@localhost ~]# mv /yum/Server/repodata /yum/Server/repodata.bak
[root@localhost ~]# mv /yum/VT/repodata /yum/VT/repodata.bak
[root@localhost ~]# mv /yum/Cluster/repodata /yum/Cluster/repodata.bak
[root@localhost ~]# mv /yum/ClusterStorage/repodata /yum/ClusterStorage/repodata.bak
第三步:安裝工具包。
[root@localhost ~]# rpm -ivh /yum/Server/createrepo-0.4.11-3.el5.noarch.rpm
第四步:重新產生倉庫資料庫。
[root@localhost ~]# createrepo -g /yum/Server/repodata.bak/comps-rhel5-server-core.xml /yum/Server/
[root@localhost ~]# createrepo -g /yum/VT/repodata.bak/comps-rhel5-vt.xml /yum/VT/
[root@localhost ~]# createrepo -g /yum/Cluster/repodata.bak/ /yum/Cluster
[root@localhost ~]# createrepo -g /yum/ClusterStorage/repodata.bak/comps-rhel5-cluster-st.xml /yum/ClusterStorage/
第五步:確認產生的檔案。
[root@localhost ~]# ls /yum/Server/repodata/
comps-rhel5-server-core.xml // 套件群組的分類
filelists.xml.gz other.xml.gz primary.xml.gz // 套件清單
repomd.xml // MD5 校驗資訊
其他三個目錄同理。往後若要新增套件,把下載好的 rpm 放進對應目錄,再重跑第四步即可。
第六步:客戶端設定,重點是紅色部分。
[root@localhost ~]# cp /etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/chenbin.repo
[root@localhost ~]# vi /etc/yum.repos.d/chenbin.repo
[rhel-Server]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///yum/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[rhel-VT]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///yum/VT
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[rhel-Cluster]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///yum/Cluster
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[rhel-ClusterStorage]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///yum/ClusterStorage
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
第七步:清快取後即可看到套件列表。

在圖形介面的「編輯 → 軟體儲存庫」中:

把勾選拿掉後,重開就不會有清單,對應設定檔中的 enabled 也會變為 0。
清除快取:
[root@localhost ~]# yum clean all
直接 rpm 安裝會因相依而失敗:
[root@localhost ~]# rpm -ivh /yum/Server/httpd-2.2.3-22.el5.i386.rpm
error: Failed dependencies:
libapr-1.so.0 is needed by httpd-2.2.3-22.el5.i386
libaprutil-1.so.0 is needed by httpd-2.2.3-22.el5.i386
改用 yum 安裝就會自動補齊:
[root@localhost ~]# yum install /yum/Server/httpd-2.2.3-22.el5.i386.rpm
[root@localhost ~]# yum remove httpd
第一步同上,複製光盤內容到 /yum。
第二步安裝 createrepo。
第三步直接在 /yum 下產生資料庫:
[root@localhost ~]# cd /yum
[root@localhost yum]# createrepo . // 注意結尾的 .
第四步確認檔案:filelists.xml.gz、other.xml.gz、primary.xml.gz、repomd.xml。
第五步設定 repo 檔,baseurl 寫 file:///yum/。
最後 yum clean all。
這種方式的好處是簡單,缺點是圖形介面的軟體清單仍然是空的,但用 yum 安裝移除完全正常。
光盤放進光機後,複製設定檔並編輯,baseurl 直接指向光機掛載點:
[root@localhost ~]# cp /etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/chenbin.repo
[root@localhost ~]# vi /etc/yum.repos.d/chenbin.repo
[rhel-Server]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///misc/cd/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
其餘 VT、Cluster、ClusterStorage 依此類推,最後 yum clean all。這種方式在圖形介面也能看到清單,但光盤一退出清單就消失。
安裝:yum install package;yum localinstall package(本機);yum groupinstall group(整組)
更新:yum update package;yum check-update;yum list updates mysql*;yum update;yum groupupdate group
查詢:yum list;yum list available;yum list installed;yum list recent;yum info
移除:yum remove package;yum groupremove group
清快取:yum clean packages/metadata/headers/all
搜尋:yum search package;yum info package;yum list package;yum list extras;yum list *ttp*
檔案歸屬:yum whatprovides filename(例如 yum whatprovides httpd.conf)
可用選項:--disablerepo=lib 停用某倉庫、--enablerepo=lib 啟用某倉庫、-C 不使用本機快取的中繼資料。例如:
yum --disablerepo=livna|--enablerepo=livna install mplayer
yum -C info httpd