YUM基础知识了解
程序员文章站
2022-05-29 10:01:39
...
YUM知识了解
YUM源:
- 本地下载软件需要的一个软件仓库,可以是本地仓库也可以是互联网在线仓库。仓库里面是.rpm包。
- 一台Linux可以添加数个YUM源,系统默认源为国外源,一般修改为国内的阿里或者清华源。
- 本地YUM仓库配置文件:
- 仓库所在目录: /etc/yum.repos.d/
Linux需要安装的源:
- base基础源
- epel扩展源
- 与服务相关的官方源
YUM扩展epel源配置
-
备份(如有配置其他epel源)
[[email protected] ~]# mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup [[email protected] ~]# mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
-
下载新repo 到/etc/yum.repos.d/
epel(RHEL 7)
[[email protected] ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
epel(RHEL 6)
[[email protected] ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
epel(RHEL 5)
[[email protected] ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo```
YUM基础base源仓库配置:
- 先备份原YUM仓库:
[[email protected] ~]# 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
[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo 或者 [[email protected] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 或者 [[email protected] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 或者 [[email protected] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
-
下载之后之后运行yum makecache生成缓存
[[email protected] ~]# yum makecache
-
YUM的使用:
-
通过仓库查找软件包→→→ yum list
[[email protected] ~]# yum list -----查看所有rpm包 [[email protected] ~]# yum list | grep nginx ---模糊匹配
-
查看软件包信息→→→ yum info
[[email protected] ~]# 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
- 搜索公网仓库直接安装
[[email protected] ~]# yum install httpd -----交互式,需确认 [[email protected] ~]# yum install httpd -y -----非交互式,直接安装
- 安装公网rpm包(自动在本地仓库查找依赖解决依赖关系)
[[email protected] ~]# yum install https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/samba-4.8.3-4.el7.x86_64.rpm
- 直接安装本地rpm包(自动在本地仓库查找依赖解决依赖关系)
[[email protected] ~]# yum localinstall samba-4.8.3-4.el7.x86_64.rpm
- 误删配置文件,重装reinstall
[[email protected] ~]# yum reinstall httpd
- 搜索公网仓库直接安装
-
YUM更新软件包
a.更新所有软件包(刚装好系统情况下更新。生产环境不执行,危险)[[email protected] ~]# yum update -y -----更新所有 [[email protected] ~]# yum update httpd -y -----指定更新某一个软件
-
删除软件包
[[email protected] ~]# yum remove httpd
-
查看正在使用的仓库信息
[[email protected] ~]# 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
-
查找某个命令或文件属于哪个软件包(常用)
- 方法一:
[[email protected] ~]# rpm -qf $(which cd) bash-4.2.46-31.el7.x86_64
- 方法二:(联网查询,查询慢)
[[email protected] ~]# yum provides cd [[email protected] ~]# yum provides /etc/my.cnf
rpm:需要知道命令的绝对路径
yum:无需知道绝对路径,只需要知道完整的命令
通过所有已启用的仓库进行查找哪些软件包中涵盖了需要查询的命令- -------查询不到的情况:
a.命令错误[[email protected] ~]# 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.清除缓存的软件包以及元数据
[[email protected] ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base epel extras updates Cleaning up list of fastest mirrors
b.只清除缓存的软件包
[[email protected] ~]# yum clean Packages [email protected] ~]# yum clean packages Loaded plugins: fastestmirror Cleaning repos: base epel extras updates 0 package files removed
转载自原文链接:https://www.ijiiyee.com