yum程序包管理简介
rpm可以实现程序的快速,简单安装(跟编译安装比),但是rpm自己不能解决依赖,所以很多工具为了自动解决依赖应运而生,其中yum就是其中之一。
yum解决依赖的办法:
必须有个文件服务器,里面放置所以的rpm包,以及包的相关元数据(-qi,-qR得到的数据)。元数据可以使用
createrepo
来创建。并放置在repodata目录下。这个文件服务器可以使用ftp,http,nfs协议来传输数据,也可以使用file:///(本地服务)。
客户端使用yum程序,安装程序包。安装时,查询文件服务器,自己从文件服务器找依赖,并安装。
yum是一个程序,查看本机是否安装了yum:
# rpm -q yumyum-3.4.3-161.el7.centos.noarch
查看yum程序所使用的配置文件:
/etc/yum.conf是主配置文件,它里面引用了目录/etc/yum.repos.d/,所以/etc/yum.repos.d/目录下的*.repo也是yum的配置文件.它提供了所以仓库的公共配置。
实现了把配置文件分割成了许多独立的小的配置文件。
/etc/yum.repos.d/目录下的*.repo:为仓库的指向提供配置信息。
# rpm -qc yum/etc/logrotate.d/yum#log用
/etc/yum.conf
/etc/yum/version-groups.conf#版本控制
/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
# This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
[main]:主配置,相当于程序的指向入口
cachedir:缓存路径
keepcache:是否保持缓存
debuglevel:调试级别
logfile:日志文件
exactarch:是否做精确匹配。如果OS是centos7,当找到的rpm包,既有centos6的也有centos7的,如果此处的值是1,则选择centos7的。
gpgcheck:安装时,是否检查完整性和来源合法性。1则检查
plugins:yum是否支持插件。1则支持
使用whatis查看是否有man帮助。
# whatis yum.confyum.conf (5) - Configuration file for yum(8).
使用:man 5 yum.conf
可以得到详细的yum.conf配置文件的详细帮助。
仓库指向的定义
[repositoryid]:仓库的id
name=仓库的名字
baseurl=url://path/to/repository/:仓库在哪里,地址可以有多个,那么选哪个呢?根据failovermethod选。
baseurl=url://server1/path/to/repository/
url://server2/path/to/repository/
url://server3/path/to/repository/
- failovermethod={roundrobin|priority}。默认为roundrobin,意味随机选一个url
- gpgcheck={1|0}:1则检查。默认是1.
- enabled={1|0}:是否使用此repo
- gpgkey=URL:公钥
- enablegroups={1|0}:1则使用组功能。默认是1.
- const=默认是1000.有多个符合就选cost小的。
centos7下/etc/yum.repos.d/下的repo配置文件有几个,只有CentOS-Base.repo文件里repo的enabled是1,也就是可以使用状态,其余的配置文件里的repo的enabled都是0.
# ls /etc/yum.repos.d/CentOS-Base.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
CentOS-Base.repo_20191129 CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
查看配置文件:/etc/yum.repos.d/CentOS-Base.repo的内容。
[base]name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
指定baseurl的技巧:指到repodata所在的网页的URL。
上面的updates的baseurl的值就是下图的网页地址栏的URL。理由是repodata在这里。
查看repo list:
# yum repolistLoaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
!base/7/x86_64 CentOS-7 - Base 10,097
!extras/7/x86_64 CentOS-7 - Extras 323
!updates/7/x86_64 CentOS-7 - Updates 1,446
repolist: 11,866
repo id:
repo name:是配置文件/etc/yum.repos.d/CentOS-Base.repo里的name的值
status:这个repo里的rmp包的数量。
yum命令介绍
yum [options][command] [package ...]
显示repo(仓库)列表(list):repolist [all|enabled|disabled]
- all:显示全部
- enabled:显示可用的。默认值。就是本地repo配置文件里enabled=1的repo会显示出来。
- disabled:显示不可用的。就是本地repo配置文件里enabled=0的repo会显示出来。
# yum repolist all
# yum repolist enabled
# yum repolist disabled
显示指定repo里有哪些rpm包:
yum list [all | glob_exp1] [glob_exp2] [...]
显示所有的包:
# yum list
可以使用glob_exp。
显示内容的第三列:repo配置文件中的repoid
# yum list php*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
php.x86_64 5.4.16-46.1.el7_7 updates
php-bcmath.x86_64 5.4.16-46.1.el7_7 updates
php-pear.noarch 1:1.9.4-21.el7 base
php-pecl-memcache.x86_64 3.0.8-4.el7 base
显示repo中还未安装的包:
yum list available [glob_exp1][...]
# yum list available
显示repo中的可以升级的包:
yum list updates [glob_exp1][...]
# yum list updates
显示已经安装的包:
yum list installed [glob_exp1][...]
- @anaconda:安装系统时,安装的包。
- installed:后来自己安装的。
# yum list installed
zlib.x86_64 1.2.7-18.el7 @anaconda
zsh.x86_64 5.0.2-33.el7 installed
显示已经安装了的extra repo中的包:
yum list extras [glob_exp1][...]
# yum list extras
显示已经安装的包,哪些已经废弃了:
yum list distro-extras [glob_exp1][...]
# yum list distro-extras
安装包:
yum install package1 [package2
如果repo里有多个版本,可以指定版本,例如:
yum install gcc-4.8.5
也可以不指定版本,则安装最新版:
yum install gcc
升级包:
yum update [package1][package2] [...]
# yum update gcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No packages marked for update
降级:
downgrade package1 [package2][...]
类似:
rpm -Uvh --oldpackage
重新覆盖安装:
reinstall package1 [package2][...]
类似:
rpm -ivh --replacepkgs
检查有哪些包可以升级:
yum check-update
卸载包:
yum remove | erase package1 [package2][...]
当卸载的包,被别的包依赖时,别的包也一并被卸载
卸载cpp:由于gcc依赖于cpp,所有如果卸载cpp,则gcc也会被卸载。
查看包的信息:
yum info [glob_exp1][...]
类似rpm -qi
# yum info gcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Packages
Name : gcc
Arch : x86_64
Version : 4.8.5
Release : 39.el7
Size : 37 M
Repo : installed
From repo : base
Summary : Various compilers (C, C++, Objective-C, Java, ...)
URL : http://gcc.gnu.org
License : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
Description : The gcc package contains the GNU Compiler Collection version 4.8.
: You'll need this package in order to compile C code
查看程序或文件是有哪个包提供的:
yum provides | whatprovides feature1 [feature2
类似rpm -qf file
# yum provides /usr/bin/gcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
gcc-4.8.5-39.el7.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)
Repo : base
Matched from:
Filename : /usr/bin/gcc
gcc-4.8.5-39.el7.x86_64 : Various compilers (C, C++, Objective-C, Java, ...)
Repo : @base
Matched from:
Filename : /usr/bin/gcc
清除元数据文件在本地的缓存:
clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
yum按文件时,会把程序包和元数据文件缓存在本地,当安装结束,yum会删除程序包文件,但是不会删除 元数据文件。
构建缓存:
yum makecache [fast]
用关键字搜索信息:
yum search string1 [string2][...]
从包名和包的summary里搜索指定的关键字。
# yum search bash
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
====================================================== N/S matched: bash =======================================================
bash-completion.noarch : Programmable completion for Bash
bash-doc.x86_64 : Documentation files for bash
libguestfs-bash-completion.noarch : Bash tab-completion scripts for libguestfs tools
libvirt-bash-completion.x86_64 : Bash completion script
pcp-pmda-bash.x86_64 : Performance Co-Pilot (PCP) metrics for the Bash shell
bash.x86_64 : The GNU Bourne Again shell
Name and summary matches only, use "search all" for everything.
显示某个包所依赖的包:
deplist package1 [package2][...]
# yum deplist gcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
package: gcc.x86_64 4.8.5-39.el7
dependency: /bin/sh
provider: bash.x86_64 4.2.46-33.el7
dependency: /sbin/install-info
provider: info.x86_64 5.1-5.el7
...
查看yum的安装,更新,卸载的历史:
yum history
不带参数则是history listhistory [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
# yum history
Loaded plugins: fastestmirror, langpacks
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
5 | root <root> | 2020-02-15 23:00 | Install | 2
4 | root <root> | 2020-02-15 22:59 | Erase | 8
3 | root <root> | 2020-02-15 22:48 | Update | 11 <
2 | ys <ys> | 2019-11-29 17:38 | Install | 8 >
1 | System <unset> | 2019-11-29 16:44 | Install | 1458
history list
上面是汇总的信息,如果想看id为5的详细信息,也就是id为5的安装了哪些包,则使用:
# yum history info 5
Loaded plugins: fastestmirror, langpacks
Transaction ID : 5
Begin time : Sat Feb 15 23:00:14 2020
Begin rpmdb : 1459:fe9d7def2a5edd098cfe39ebe0732b67038170b5
End time : 23:00:19 2020 (5 seconds)
End rpmdb : 1461:ed3657ce694e0e90ea8bf62a092f06422c81ac28
User : root <root>
Return-Code : Success
Command Line : install gcc
Transaction performed with:
Installed rpm-4.11.3-35.el7.x86_64 @anaconda
Installed yum-3.4.3-161.el7.centos.noarch @anaconda
Installed yum-plugin-fastestmirror-1.1.31-50.el7.noarch @anaconda
Packages Altered:
Dep-Install cpp-4.8.5-39.el7.x86_64 @base
Install gcc-4.8.5-39.el7.x86_64 @base
history info
查看yumdb大小:
# yum history stats
Loaded plugins: fastestmirror, langpacks
File : //var/lib/yum/history/history-2020-02-16.sqlite
Size : 23,552
Transactions: 0
history stats
本地安装/升级:想安装的包在yum repo中没有,可以下载一个rpm包安装。但为什么不用rpm呢,因为rpm不能解决依赖,而yum可以,所以即使是本地的rpm包,也可以使用yum安装,但是参数是rpm文件名。
localinstall/localupdate是为了兼容以前的版本,应该使用intall/update 参数是rpm文件名。
localinstall rpmfile1 [rpmfile2][...]
(maintained for legacy reasons only - use install)
localupdate rpmfile1 [rpmfile2][...]
(maintained for legacy reasons only - use update)
组安装/更新/卸载/查看
查看有哪些组可供安装:
# yum groups list
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Installed Groups:
Development Tools
Available Groups:
Compatibility Libraries
Console Internet Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
查看某个组里有哪些包:
# yum groups info Development Tools
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Group: Development Tools
Group-Id: development
Description: A basic development environment.
Mandatory Packages:
gcc
=gcc-c++
gettext
=libtool
make
Default Packages:
byacc
=gcc-gfortran
swig
=systemtap
Optional Packages:
ElectricFence
ant
babel
bzr
Mandatory Packages:必须安装的包
Default Packages:默认安装的包
Optional Packages:可选安装的包
安装:
# yum groups install "Development Tools"
更新:
# yum groups update "Development Tools"
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Maybe run: yum groups mark install (see man yum)
No packages in any requested group available to install or updates
删除:
# yum groups remove Development Tools
拿光盘作为repo
1,先挂载centos系统安装盘到/media目录。
2,创建文件local.repo
[base]name=local repo centos
baseurl=file:///media/
enabled=1
gpgcheck=0
3,然后就可以正常使用yum命令了。
c/c++ 学习互助QQ群:877684253
本人微信:xiaoshitou5854
以上是 yum程序包管理简介 的全部内容, 来源链接: utcz.com/z/513500.html