yum客户端:
配置文件:
/etc/yum.conf:为所有仓库提供公共配置
/etc/yum.repos.d/*.repo:为仓库的指向提供配置
仓库指向的定义:
[repositoryID]
name=Some name for this repository
baseurl=url://path/to/repository/
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL
enablegroups={1|0}
failovermethod={roundrobin|priority}
默认为:roundrobin,意为随机挑选;
cost=
默认为1000z
首先配置yum仓库,以centos7指向网易镜像源为例
进到http://mirrors.163.com
按照操作手册安装yum客户端
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]
#yum repolist all
显示程序包:
list
# yum list [all | glob_exp1] [glob_exp2] [...]
# yum list {available|installed|updates} [glob_exp1] [...]
安装程序包:
install package1 [package2] [...]
reinstall package1 [package2] [...] (重新安装)
#yum install gcc
升级程序包:
update [package1] [package2] [...]
downgrade package1 [package2] [...] (降级)
检查可用升级:
check-update
卸载程序包:
remove | erase package1 [package2] [...]
#yum remove gcc
#yum erase gcc
查看程序包information:
info [...]
#yum info gcc
查看指定的特性(可以是某文件)是由哪个程序包所提供:
provides | whatprovides feature1 [feature2] [...]
#yum provides gcc
清理本地缓存:
clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
#yum clean all
构建缓存:
makecache
#yum makecache
搜索:
search string1 [string2] [...]
#yum search gcc
以指定的关键字搜索程序包名及summary信息;
查看指定包所依赖的capabilities:
deplist package1 [package2] [...]
查看yum事务历史:
history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
#yum history list
安装及升级本地程序包:
用yum命令安装rpm包,可以直接用install代替localinstall
* 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仓库:
(1) 挂载光盘至某目录,例如/media/cdrom
# mount -r -t iso9660 /dev/cdrom /media/cdrom
(2) 创建配置文件
[CentOS7]
name=
baseurl=
gpgcheck=
enabled=
yum的命令行选项:
--nogpgcheck:禁止进行gpg check;
-y: 自动回答为“yes”;
-q:静默模式;
--disablerepo=repoidglob:临时禁用此处指定的repo;
--enablerepo=repoidglob:临时启用此处指定的repo;
--noplugins:禁用所有插件;
yum的repo配置文件中可用的变量:
$releasever: 当前OS的发行版的主版本号;
$arch: 平台;
$basearch:基础平台;
$YUM0-$YUM9
创建本地yum仓库:
createrepo [options] <directory>
测试:下载rpm包
# wget http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages
# cat Packages | awk -F\> '{print $1}' | awk -F= '{print $2}' | awk -F\" '{print "wget http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages/"$2}' | grep 'rpm' > downloadrpm.sh
# ./downloadrpm.sh
#createrepo /yum/repo/ 在/yum/repo/下生成repodata
#cd /yum/repo/repodata
#ls
#cd /etc/yum.repos.d/
#vim CentOS7-Base-163.repo 添加本地yum源 [test] name=test baseurl=file:///yum/repo/ gpgcheck=0
#yum makecache 或者#yum repolist