YUM軟件倉庫管理
YUM源:
- 本地下載軟件需要的一個軟件倉庫,可以是本地倉庫也可以是互聯網在線倉庫。倉庫裏面是.rpm包。
- 一臺Linux可以添加數個YUM源,系統默認源爲國外源,一般修改爲國內的阿里或者清華源。
- 本地YUM倉庫配置文件:
- 倉庫所在目錄: /etc/yum.repos.d/
Linux需要安裝的源:
- base基礎源
- epel擴展源
- 與服務相關的官方源
YUM擴展epel源配置
-
備份(如有配置其他epel源)
[root@ljc ~]# mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup [root@ljc ~]# mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
-
下載新repo 到/etc/yum.repos.d/
epel(RHEL 7)
[root@ljc ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
epel(RHEL 6)
[root@ljc ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
epel(RHEL 5)
[root@ljc ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo```
YUM基礎base源倉庫配置:
- 先備份原YUM倉庫:
[root@ljc ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- 安裝阿里雲yum源倉庫
-
下載新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
[root@ljc ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo 或者 [root@ljc ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
[root@ljc ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 或者 [root@ljc ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
[root@ljc ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 或者 [root@ljc ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
-
下載之後之後運行yum makecache生成緩存
[root@ljc ~]# yum makecache
-
YUM的使用:
-
通過倉庫查找軟件包→→→ yum list
[root@ljc ~]# yum list -----查看所有rpm包 [root@ljc ~]# yum list | grep nginx ---模糊匹配
-
查看軟件包信息→→→ yum info
[root@ljc ~]# yum info httpd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Installed Packages Name : httpd Arch : x86_64 Version : 2.4.6 Release : 88.el7.centos Size : 9.4 M Repo : installed 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 install
- 搜索公網倉庫直接安裝
[root@ljc ~]# yum install httpd -----交互式,需確認 [root@ljc ~]# yum install httpd -y -----非交互式,直接安裝
- 安裝公網rpm包(自動在本地倉庫查找依賴解決依賴關係)
[root@ljc ~]# yum install https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/samba-4.8.3-4.el7.x86_64.rpm
- 直接安裝本地rpm包(自動在本地倉庫查找依賴解決依賴關係)
[root@ljc ~]# yum localinstall samba-4.8.3-4.el7.x86_64.rpm
- 誤刪配置文件,重裝reinstall
[root@ljc ~]# yum reinstall httpd
- 搜索公網倉庫直接安裝
-
YUM更新軟件包
a.更新所有軟件包(剛裝好系統情況下更新。生產環境不執行,危險)[root@ljc ~]# yum update -y -----更新所有 [root@ljc ~]# yum update httpd -y -----指定更新某一個軟件
-
刪除軟件包
[root@ljc ~]# yum remove httpd
-
查看正在使用的倉庫信息
[root@ljc ~]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com repo id repo name status base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,019 epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,082 extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 386 updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,580 repolist: 25,067
-
查找某個命令或文件屬於哪個軟件包(常用)
- 方法一:
[root@ljc ~]# rpm -qf $(which cd) bash-4.2.46-31.el7.x86_64
- 方法二:(聯網查詢,查詢慢)
[root@ljc ~]# yum provides cd [root@ljc ~]# yum provides /etc/my.cnf
rpm:需要知道命令的絕對路徑
yum:無需知道絕對路徑,只需要知道完整的命令
通過所有已啓用的倉庫進行查找哪些軟件包中涵蓋了需要查詢的命令- -------查詢不到的情況:
a.命令錯誤[root@ljc ~]# yum provides nginx-1.15.12.tar.gz Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com No matches found
b.倉庫不存在(添加更多的yum倉庫)
- 方法一:
-
清除緩存
a.清除緩存的軟件包以及元數據
[root@ljc ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base epel extras updates Cleaning up list of fastest mirrors
b.只清除緩存的軟件包
[root@ljc ~]# yum clean Packages root@ljc ~]# yum clean packages Loaded plugins: fastestmirror Cleaning repos: base epel extras updates 0 package files removed
轉載自原文鏈接:https://www.ijiiyee.com