Yum (full name Yellow dog Updater, Modified) is a package management tool based on RPM packages, which can automatically download and install RPM packages from a specified server, automatically handle dependencies, and install all dependent packages at one time, without tedious Download and install again and again. As for the introduction of RPM, please refer to http://blog.51cto.com/marvin89/2107904
Simple flow chart of yum:
yum configuration file view
[root@localhost Packages]# rpm -q yum
yum-3.4.3-154.el7.centos.noarch
[root@localhost Packages]# rpm -qc yum
/etc/logrotate.d/yum
/etc/yum.conf
/etc/yum/version-groups.conf
The configuration file is divided into 2 ends
[root@localhost Packages]# man yum.conf
#主配置
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0 #
debuglevel=2
logfile=/var/log/yum.log
exactarch=1 #centos6 centos7 之类是否精确匹配
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
#仓库配置
[repositoryID]
name=Some name for this repository #介绍
baseurl=url://path/to/repository/ #必须跟repodata同一个目录
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL #公钥
enablegroups={1|0} #用组的方式管理程序包
failovermethod={roundrobin|priority}
默认为:roundrobin,意为随机挑选; baseurl
cost=默认为1000 权重越高优先使用
Configure yum with centos CD as repository
Prepare the yum source CD
[root@localhost rpm]# cd /mnt/dvd/
[root@localhost dvd]# ls
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
Configure the repository
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/local.repo
[base]
name=Base repo from cd
baseurl=file:///mnt/dvd/
gpgcheck=1
gpgkey=file:///mnt/dvd/RPM-GPG-KEY-CentOS-7
1. Display the warehouse list:
#repolist [all|enabled|disabled]
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
!base Base repo from cd 9,591
repolist: 9,591
2. Installation
[root@localhost yum.repos.d]# yum install zsh-html [#-y] 默认安装最新版本,安装老版本需要手动指定
3. Upgrade, check the upgrade (it can also be a local package)
#升级
[root@localhost yum.repos.d]# yum update zsh-html
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
No packages marked for update
-----------------------------------------------------------
#检查升级
[root@localhost yum.repos.d]# yum check-update zsh-html
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
4. Uninstall will only uninstall the current package and the package that depends on the current package
will not delete the package that depends on ImageMagick during installation because these packages depend on ImageMagick, not depend on
[root@localhost yum.repos.d]# yum install ImageMagick
Dependencies Resolved
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Installing:
ImageMagick x86_64 6.7.8.9-15.el7_2 base 2.1 M
Installing for dependencies:
OpenEXR-libs x86_64 1.7.1-7.el7 base 217 k
avahi-libs x86_64 0.6.31-17.el7 base 61 k
cairo x86_64 1.14.8-2.el7 base 713 k
cups-libs x86_64 1:1.6.3-29.el7 base 356 k
fontconfig x86_64 2.10.95-11.el7 base 229 k
fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k
gdk-pixbuf2 x86_64 2.36.5-1.el7 base 567 k
ghostscript x86_64 9.07-28.el7 base 4.3 M
ghostscript-fonts noarch 5.50-32.el7 base 324 k
graphite2 x86_64 1.3.6-1.el7_2 base 112 k
harfbuzz x86_64 1.3.2-1.el7 base 177 k
ilmbase x86_64 1.0.3-7.el7 base 100 k
jasper-libs x86_64 1.900.1-31.el7 base 150 k
.....
[root@localhost yum.repos.d]# yum remove ImageMagick
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package ImageMagick.x86_64 0:6.7.8.9-15.el7_2 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Removing:
ImageMagick x86_64 6.7.8.9-15.el7_2 @base 7.6 M
Transaction Summary
=============================================================================================
Remove 1 Package
Uninstalling ImageMagick's dependency package OpenEXR-libs will also uninstall ImageMagick
[root@localhost yum.repos.d]# yum remove OpenEXR-libs
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package OpenEXR-libs.x86_64 0:1.7.1-7.el7 will be erased
--> Processing Dependency: libIlmImf.so.7()(64bit) for package: ImageMagick-6.7.8.9-15.el7_2.x86_64
--> Running transaction check
---> Package ImageMagick.x86_64 0:6.7.8.9-15.el7_2 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================
Package Arch Version Repository Size
=============================================================================================
Removing:
OpenEXR-libs x86_64 1.7.1-7.el7 @base 844 k
Removing for dependencies:
ImageMagick x86_64 6.7.8.9-15.el7_2 @base 7.6 M
Personally, I think this uninstall method is not very good, and there will be a lot of useless packages left.
5.
Display the package:
# yum list [all | glob_exp1] [glob_exp2] [...]
# yum list {available|installed|updates} [glob_exp1] [...]
[root@localhost yum.repos.d]# yum list
Installed Packages
GeoIP.x86_64 1.5.0-11.el7 @anaconda #@表示安装过的。anaconda表示操作系统
....
zziplib-devel.i686 0.13.62-5.el7 base #还未安装的
zziplib-devel.x86_64 0.13.62-5.el7 base
zsh-html.x86_64 5.0.2-28.el7 @base #base源安装的
6. View specific package information
[root@localhost yum.repos.d]# yum info ImageMagick
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name : ImageMagick
Arch : x86_64
Version : 6.7.8.9
Release : 15.el7_2
Size : 7.6 M
Repo : installed
From repo : base
Summary : An X application for displaying and manipulating images
....
7. Check which package provides the specified feature (which can be a file): equivalent to rpm -qf
# provides | whatprovides feature1 [feature2] [...]
[root@localhost yum.repos.d]# yum provides /etc/passwd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
setup-2.8.71-7.el7.noarch : A set of system configuration and setup files
Repo : base
Matched from:
Filename : /etc/passwd
setup-2.8.71-7.el7.noarch : A set of system configuration and setup files
Repo : @anaconda
Matched from:
Filename : /etc/passwd
8. View the search package name and summary information with the specified keyword;
[root@localhost yum.repos.d]# yum search zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
===================================== N/S matched: zsh ======================================
zsh-html.x86_64 : Zsh shell manual in html format
zsh.x86_64 : Powerful interactive shell
Name and summary matches only, use "search all" for everything.
9. Dependency package view
[root@localhost yum.repos.d]# yum deplist bash
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
package: bash.x86_64 4.2.46-28.el7
dependency: libc.so.6(GLIBC_2.15)(64bit)
provider: glibc.x86_64 2.17-196.el7
dependency: libdl.so.2()(64bit)
......
10. View yum transaction history:
#history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
[root@localhost yum.repos.d]# yum history
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
17 | root <root> | 2018-04-25 21:53 | Install | 1
16 | root <root> | 2018-04-25 21:49 | Erase | 1
15 | root <root> | 2018-04-25 21:49 | Install | 48
11. View package group
[root@localhost yum.repos.d]# yum grouplist
Installed Groups:
.....
Available Groups:
Compatibility Libraries
Console Internet Tools
Graphical Administration Tools
Development Tools
.....
12. Installation package group
[root@localhost yum.repos.d]# yum groupinstall "Development Tools"
# 升级 groupupdate group1 [group2] [...]
13. Remove the package group
[root@localhost yum.repos.d]# yum groupremove "Development Tools"
14. View package group information
[root@localhost yum.repos.d]# yum groupinfo "Development Tools"
Build your own yum source
1. Add several rpm packages for yum source
[root@localhost yum.repos.d]# mkdir -p /yum/repo
[root@localhost yum.repos.d]# cp /mnt/dvd/Packages/z* /yum/repo/
2, centos7 needs to install createrepo
[root@localhost repo]# yum install createrepo
3. Initialize the warehouse
[root@localhost repo]# pwd
/yum/repo
[root@localhost repo]# createrepo ../ #在上级目录下创建repodata
Spawning worker 0 with 5 pkgs
Spawning worker 1 with 5 pkgs
Spawning worker 2 with 5 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost repo]# cd ..
[root@localhost yum]# ls repodata
447ec135b1c7f6b6270eefc3c48487b7111af058b6a8e69d2752dff8fe692f10-filelists.sqlite.bz2
5bf5f6ef05024c6fa8323255156d043213eac62f765d4106d71e57e133e16990-other.xml.gz
6c2ee7607b3b821acc6907604067e85d101fb4eecc6e10baa45086f26e0343f8-primary.sqlite.bz2
c881c0f911ca54a1ade1d96280a04b8224a5d782522d555f7c6d1b528c2ddd7f-other.sqlite.bz2
e018c8c524d20f6f30d26b42c909757eb2966a55c2f1a90d543602848db03384-filelists.xml.gz
ed266c67e84620208b4124883f03e6a8eaf0ba1d98a0dddd85c5a57beb8efbc4-primary.xml.gz
repomd.xml
4. Edit the configuration file
[myrepo]
name=test repo
baseurl=file:///yum
gpgcheck=0
5. Use your own yum source
[root@localhost repodata]# yum remove zsh
[root@localhost repodata]# yum install zsh
Loaded plugins: fastestmirror
myrepo | 2.9 kB 00:00
myrepo/primary_db | 9.2 kB 00:00
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
zsh x86_64 5.0.2-28.el7 myrepo 2.4 M
Transaction Summary
===============================================================================
Install 1 Package
Total download size: 2.4 M
Installed size: 5.6 M
Is this ok [y/d/N]: