一、yum简介
yum是解决rpm软件包的依赖性而开发的一种软件包管理器。yum 的宗旨是自动化地升级,安装/移除rpm 包,收集rpm 包的相关信息,检查依赖性并自动提示用户解决。yum 的关键之处是要有可靠的repository,顾名思义,这是软件的仓库,它可以是http 或ftp 站点。
二、yum安装
CentOS 默认已经安装了yum,不需要另外安装
1、查看系统默认安装的yum
[root@localhost ~]# rpm -qa |grep yum yum-utils-1.1.31-45.el7.noarch yum-plugin-fastestmirror-1.1.31-45.el7.noarch PackageKit-yum-1.1.5-1.el7.centos.x86_64 yum-metadata-parser-1.1.4-10.el7.x86_64 yum-langpacks-0.4.2-7.el7.noarch yum-3.4.3-158.el7.centos.noarch
三、yum配置文件
yum客户端配置文件:
/etc/yum.conf:为所有仓库提供公共配置
[root@localhost ~]# cat /etc/yum.conf [main] cachedir=/var/cache/yum/$basearch/$releasever keepcache=0 debuglevel=2 logfile=/var/log/yum.log exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release
/etc/yum.repos.d/*.repo:为仓库的指向提供配置
[repoid] 仓库的名称,不能重复,独一无二
name= 仓库的描述,可以不写,将会用repoid当作name
enabled=1|0 激活或禁用仓库,若不写该行,则默认启用
gpgcheck=1|0 是否在安装包是检测gpg签名,默认检测,即为1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 指定gpg key的路径
[root@localhost rpm-gpg]# ls RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Debug-7 RPM-GPG-KEY-CentOS-Testing-7 [root@localhost rpm-gpg]# pwd /etc/pki/rpm-gpg
四、yum仓库的创建
yum的repo配置文件中可用的变量:
$releasever: 当前OS的发行版的主版本号
$arch: 平台,i386,i486,i586,x86_64等
$basearch:基础平台;i386, x86_64
$YUM0-$YUM9:自定义变量
• 实例:
http://server/centos/$releasever/$basearch/
http://server/centos/6/i384
[root@localhost ~]# vim /etc/yum.repos.d/fhj.repo [root@localhost ~]# cat /etc/yum.repos.d/fhj.repo [base] name=Red Hat Enterprise Linux $releasever Repo baseurl=http://172.18.0.1/centos/$releasever enabled=1 #教师机yum源镜像 gpgcheck=0 [base] name=Red Hat Enterprise Linux $releasever Repo baseurl=file:///media #本地yum源镜像 enabled=1 gpgcheck=0 [epel] name=mage epel $releasever baseurl=http://172.18.0.1/fedora-epel/$releasever/$basearch enabled=1 gpgcheck=0 #第三方库文件 使用在线epel [epel] name=mage epel baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/ enabled=1 gpgcheck=0
自动生成仓库
[root@localhost ~]# yum-config-manager --add "https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/" Loaded plugins: fastestmirror, langpacks Repository base is listed more than once in the configuration adding repo from: https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/ [mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_] name=added from: https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/ baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/ enabled=1
五、yum命令
用法:yum 选项 命令 包名
yum clean all 清空yum缓存
yum makecache 重建缓存,(没有缓存时,首次使用yum的任何命令都会自动重建)
显示仓库列表
[root@localhost ~]# yum repolist all Loaded plugins: fastestmirror, langpacks Repository base is listed more than once in the configuration Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.huaweicloud.com repo id repo name status C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base disabled C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus disabled C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras disabled C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus disabled C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates disabled C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base disabled C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus disabled C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras disabled C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus disabled C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates disabled C7.2.1511-base/x86_64 CentOS-7.2.1511 - Base disabled C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus disabled C7.2.1511-extras/x86_64 CentOS-7.2.1511 - Extras disabled [root@localhost ~]# yum repolist enabled Loaded plugins: fastestmirror, langpacks Repository base is listed more than once in the configuration Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.huaweicloud.com repo id repo name status base/7/x86_64 CentOS-7 - Base 9,911 epel/7/x86_64 mage epel 7 11,349 extras/7/x86_64 CentOS-7 - Extras 368 updates/7/x86_64 CentOS-7 - Updates 1,041 repolist: 22,669
显示程序包
yum list
base 未安装的包,来自于base
epel 未安装的包,来自于epel
@base 该包已经安装,且是从base安装的
@anaconda 该包已经安装,且是从操作系统的安装程序anaconda安装的
all 默认 表示列出所有包
updates 列出可更新的包
installed 列出已安装的包
@repoid 表示该包安装自指定的仓库
installed 表示该包由rpm命令手工安装
安装程序包:
[root@localhost ~]# yum install samba
重新安装
[root@localhost ~]# yum reinstall tree
检查可用升级
[root@localhost ~]# yum check-update
升级程序包
[root@localhost ~]# yum update sudo
卸载程序包
[root@localhost ~]# yum remove sudo 卸载时不会连同依赖包一同卸载
查看指定包的详细信息
[root@localhost ~]# yum info tree
搜索一个文件来自于哪个rpm包,可以是未安装的包
yum provides "*/rz" [root@localhost ~]# yum provides "*/rz" Loaded plugins: fastestmirror, langpacks Repository base is listed more than once in the configuration Loading mirror speeds from cached hostfile * base: mirrors.huaweicloud.com * extras: mirrors.huaweicloud.com * updates: mirrors.huaweicloud.com mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ | 3.2 kB 00:00:00 (1/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/group_gz | 88 kB 00:00:00 (2/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/updateinfo | 932 kB 00:00:00 (3/3): mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/primary | 3.6 MB 00:00:00 mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ 12629/12629 base/7/x86_64/filelists_db | 6.9 MB 00:00:00 epel/7/x86_64/filelists_db | 7.6 MB 00:00:00 extras/7/x86_64/filelists_db | 588 kB 00:00:00 mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_/filelists | 10 MB 00:00:01 updates/7/x86_64/filelists_db | 2.4 MB 00:00:00 lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs Repo : base Matched from: Filename : /usr/bin/rz lrzsz-0.12.20-36.el7.x86_64 : The lrz and lsz modem communications programs Repo : @anaconda Matched from: Filename : /usr/bin/rz
模糊搜索 软件包和描述
yum search 关键字
[root@localhost ~]# yum search samba
列出指定包所依赖的所有包
yum deplist php
yum history 列出所有的yum历史
info # 查看某条历史的详细信息
redo # 重做某条历史
undo # 撤消某条历史
如果该历史为install,则undo 是remove
如果该历史为remove,则undo 是install
注意:撤销某条历史(某个包的安装),安装的包会连同它的依赖包一同删除
安装本地的包
yum [local]install /path/*.rpm [root@localhost ~]# yum install /media/Packages/php-5.4.16-45.el7.x86_64.rpm