Package Management of CentOS System: yum

Keywords: yum CentOS RPM Apache

Package Management of CentOS System: yum

Introduction to yum

YUM (Yellowdog Update Modifier) is the front-end program of rpm. It can solve the dependency of software packages, locate software packages among libraries, and is an alternative tool of up2date.

# CentOS: yum, dnf

# yum repository: yum repo
	# Stores many rpm packages, as well as their associated metadata files (placed under a specific directory repodata)

# File Server:
	http://
	https://
	ftp://
	file://

yum client

yum client configuration file path:

# /etc/yum.conf                # Provide common configuration for all warehouses
# /etc/yum.repos.d/*.repo      # Provide configuration for warehouse direction

/etc/yum.conf

/ etc/yum.conf defines the working characteristics of yum. Using man yum.conf, you can see the specific meaning.

# cat /etc/yum.conf
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1       # Precise and rigorous platform matching
obsoletes=1
gpgcheck=1        # Checking Legitimacy and Integrity
plugins=1         # Support plug-in mechanism
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

Warehouse Pointing Definition

[repositoryID]
name=Some name for this repository
baseurl=url://No spaces can be left around path/to/repository/#= and multiple URL s can be created.
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL                           #  gpg key file access path
enablegroups={1|0}
failovermethod={roundrobin|priority}
	# The default is: roundrobin, meaning random selection;
cost=           
	# Overhead value, default 1000

View the local yum source

# yum repolist  
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
repo id                   repo name                   status
base/7/x86_64             CentOS-7 - Base              10,019
extras/7/x86_64           CentOS-7 - Extras            419
updates/7/x86_64          CentOS-7 - Updates           2,124
repolist: 12,562

Usage of the yum command

Grammatical Format:

# yum [options] [command] [package ...]

Command command options

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]   Help

Display warehouse list

# yum repolist [all|enabled|disabled]

Display package

# list

   # yum list [all | glob_exp1] [glob_exp2] [...]
 	 # For wildcards
    		
   # yum list {available|installed|updates} [glob_exp1] [...]
   	 # available: available     
  	 # installed: installed  
 	 # Updates: updates

Examples:

[root@LeeMumu etc]# yum list installed
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror.jdcloud.com
Installed Packages
GeoIP.x86_64              1.5.0-13.el7           @anaconda
NetworkManager.x86_64     1:1.12.0-6.el7         @anaconda
... ...
[root@LeeMumu etc]# yum list "*device*"
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror.jdcloud.com
Installed Packages
device-mapper.x86_64                                         7:1.02.149-8.el7                           @anaconda
device-mapper-event.x86_64                                   7:1.02.149-8.el7                           @anaconda
device-mapper-event-libs.x86_64                              7:1.02.149-8.el7                           @anaconda
device-mapper-libs.x86_64                                    7:1.02.149-8.el7                           @anaconda
device-mapper-persistent-data.x86_64                         0.7.3-3.el7                                @anaconda
Available Packages
corosync-qdevice.x86_64                                      2.4.3-4.el7                                base     
device-mapper.x86_64                                         7:1.02.149-10.el7_6.8                      updates  
... ... 
libimobiledevice-python.x86_64                               1.2.0-1.el7                                base     
libimobiledevice-utils.x86_64                                1.2.0-1.el7                                base     
[root@LeeMumu etc]# yum list available | grep "*wireshark*"
Repository base is listed more than once in the configuration
[root@LeeMumu etc]# yum list available | grep "wireshark*"
Repository base is listed more than once in the configuration
wireshark.i686                            1.10.14-16.el7                 base   
wireshark.x86_64                          1.10.14-16.el7                 base   
wireshark-devel.i686                      1.10.14-16.el7                 base   
wireshark-devel.x86_64                    1.10.14-16.el7                 base   
wireshark-gnome.x86_64                    1.10.14-16.el7                 base   

Installation package

Grammatical Format:

# yum install package1 [package2] [...]

# Yum reinstall package 1 [package 2] [...] (reinstallation)

Examples:

[root@LeeMumu ~]# yum install wireshark -y
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror.jdcloud.com
base                                                                                      | 3.6 kB  00:00:00     
extras                                                                                    | 3.4 kB  00:00:00     
updates                                                                                   | 3.4 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package wireshark.x86_64 0:1.10.14-16.el7 will be installed
--> Processing Dependency: libsmi.so.2()(64bit) for package: wireshark-1.10.14-16.el7.x86_64
--> Processing Dependency: libpcap.so.1()(64bit) for package: wireshark-1.10.14-16.el7.x86_64
--> Processing Dependency: libcares.so.2()(64bit) for package: wireshark-1.10.14-16.el7.x86_64
--> Running transaction check
---> Package c-ares.x86_64 0:1.10.0-3.el7 will be installed
---> Package libpcap.x86_64 14:1.5.3-11.el7 will be installed
---> Package libsmi.x86_64 0:0.4.8-13.el7 will be installed
--> Processing Dependency: wget for package: libsmi-0.4.8-13.el7.x86_64
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                   Arch                   Version                          Repository               Size
=================================================================================================================
Installing:
 wireshark                 x86_64                 1.10.14-16.el7                   base                     13 M
Installing for dependencies:
 c-ares                    x86_64                 1.10.0-3.el7                     base                     78 k
 libpcap                   x86_64                 14:1.5.3-11.el7                  base                    138 k
 libsmi                    x86_64                 0.4.8-13.el7                     base                    2.3 M
 wget                      x86_64                 1.14-18.el7_6.1                  updates                 547 k

Transaction Summary
=================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 16 M
Installed size: 86 M
Downloading packages:
(1/5): libpcap-1.5.3-11.el7.x86_64.rpm                                                    | 138 kB  00:00:00     
(2/5): wget-1.14-18.el7_6.1.x86_64.rpm                                                    | 547 kB  00:00:00     
(3/5): c-ares-1.10.0-3.el7.x86_64.rpm                                                     |  78 kB  00:00:00     
(4/5): libsmi-0.4.8-13.el7.x86_64.rpm                                                     | 2.3 MB  00:00:00     
(5/5): wireshark-1.10.14-16.el7.x86_64.rpm                                                |  13 MB  00:00:01     
-----------------------------------------------------------------------------------------------------------------
Total                                                                            9.9 MB/s |  16 MB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 14:libpcap-1.5.3-11.el7.x86_64                                                                1/5 
  Installing : c-ares-1.10.0-3.el7.x86_64                                                                    2/5 
  Installing : wget-1.14-18.el7_6.1.x86_64                                                                   3/5 
  Installing : libsmi-0.4.8-13.el7.x86_64                                                                    4/5 
  Installing : wireshark-1.10.14-16.el7.x86_64                                                               5/5 
  Verifying  : wireshark-1.10.14-16.el7.x86_64                                                               1/5 
  Verifying  : libsmi-0.4.8-13.el7.x86_64                                                                    2/5 
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                                                   3/5 
  Verifying  : c-ares-1.10.0-3.el7.x86_64                                                                    4/5 
  Verifying  : 14:libpcap-1.5.3-11.el7.x86_64                                                                5/5 

Installed:
  wireshark.x86_64 0:1.10.14-16.el7                                                                              

Dependency Installed:
  c-ares.x86_64 0:1.10.0-3.el7         libpcap.x86_64 14:1.5.3-11.el7        libsmi.x86_64 0:0.4.8-13.el7       
  wget.x86_64 0:1.14-18.el7_6.1       

Complete!

Upgrade package

Grammatical Format:

# yum update [package1] [package2] [...]

# Yum downgrade package 1 [package 2] [...] (downgrade)

Check available upgrades

Grammatical Format:

# yum check-update [package]

Examples:

[root@LeeMumu ~]# yum check-update httpd
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror.jdcloud.com

Unloading packages

# yum [ remove | erase ] package1 [package2] [...]

Examples:

[root@LeeMumu ~]# yum remove wireshark -y
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Resolving Dependencies
--> Running transaction check
---> Package wireshark.x86_64 0:1.10.14-16.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                    Arch                    Version                         Repository              Size
=================================================================================================================
Removing:
 wireshark                  x86_64                  1.10.14-16.el7                  @base                   67 M

Transaction Summary
=================================================================================================================
Remove  1 Package

Installed size: 67 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : wireshark-1.10.14-16.el7.x86_64                                                               1/1 
  Verifying  : wireshark-1.10.14-16.el7.x86_64                                                               1/1 

Removed:
  wireshark.x86_64 0:1.10.14-16.el7                                                                              

Complete!

View package information

Grammatical Format:

# yum info [...]

Examples:

[root@LeeMumu ~]# yum info wireshark
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror.jdcloud.com
Available Packages
Name        : wireshark
Arch        : i686
Version     : 1.10.14
Release     : 16.el7
Size        : 11 M
Repo        : base/7/x86_64
Summary     : Network traffic analyzer
URL         : http://www.wireshark.org/
License     : GPL+
Description : Wireshark is a network traffic analyzer for Unix-ish operating systems.
            : 
            : This package lays base for libpcap, a packet capture and filtering
            : library, contains command-line utilities, contains plugins and
            : documentation for wireshark. A graphical user interface is packaged
            : separately to GTK+ package.

Name        : wireshark
Arch        : x86_64
Version     : 1.10.14
Release     : 16.el7
Size        : 13 M
Repo        : base/7/x86_64
Summary     : Network traffic analyzer
URL         : http://www.wireshark.org/
License     : GPL+
Description : Wireshark is a network traffic analyzer for Unix-ish operating systems.
            : 
            : This package lays base for libpcap, a packet capture and filtering
            : library, contains command-line utilities, contains plugins and
            : documentation for wireshark. A graphical user interface is packaged
            : separately to GTK+ package.

View which package provides the specified feature (which can be a file)

Grammatical Format:

# yum [ provides | whatprovides ] feature1 [feature2] [...]

Examples:

[root@LeeMumu ~]# which ssh
/usr/bin/ssh
[root@LeeMumu ~]# yum provides /usr/bin/ssh
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror.jdcloud.com
openssh-clients-7.4p1-16.el7.x86_64 : An open source SSH client applications
Repo        : base
Matched from:
Filename    : /usr/bin/ssh
openssh-clients-7.4p1-16.el7.x86_64 : An open source SSH client applications
Repo        : @anaconda
Matched from:
Filename    : /usr/bin/ssh

Clean up local cache

Grammatical Format:

# yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]

Examples:

[root@LeeMumu ~]# yum clean dbcache
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Cleaning repos: base extras updates
12 sqlite files removed

Build caches (generally not necessary)

Grammatical Format:

# yum makecache

search

Search package names and summary information with the specified keywords.

Grammatical Format:

# yum search string1 [string2] [...]

Examples:

[root@LeeMumu ~]# yum search httpd
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror.jdcloud.com
(1/3): extras/7/x86_64/primary_db                                | 205 kB  00:00:00     
(2/3): base/7/x86_64/primary_db                                  | 6.0 MB  00:00:01     
(3/3): updates/7/x86_64/primary_db                               | 6.5 MB  00:00:01     
============================================== N/S matched: httpd ============================
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
python2-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server

  Name and summary matches only, use "search all" for everything.

View capabilities on which a specified package depends

Grammatical Format:

# yum deplist package1 [package2] [...]

Examples:

[root@LeeMumu ~]# yum deplist httpd
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirror.jdcloud.com
package: httpd.x86_64 2.4.6-89.el7.centos
  dependency: /bin/sh
... ...

View yum transaction history

Grammatical Format:

# yum history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]

# stats is used more often

Examples:

[root@LeeMumu ~]# yum history stats
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
File        : //var/lib/yum/history/history-2019-06-23.sqlite
Size        : 561,152
Transactions: 14
Begin time  : Sat Jun 22 20:09:27 2019
End time    : Sat Jul 27 10:46:32 2019
Counts      :
  NEVRAC :    456
  NEVRA  :    456
  NA     :    446
  NEVR   :    456
  rpm DB :    456
  yum DB :    456
history stats

Install and upgrade local packages

Grammatical Format:

# yum localinstall rpmfile1 [rpmfile2] [...]
	 (maintained for legacy reasons only - use install)
# yum localupdate rpmfile1 [rpmfile2] [...]
      (maintained for legacy reasons only - use update)

Examples:

Insert code slices here

Relevant commands for package management

Grammatical Format:

# yum groupinstall group1 [group2] [...]
# yum groupupdate group1 [group2] [...]
# yum grouplist [hidden] [groupwildcard] [...]
# yum groupremove group1 [group2] [...]
# yum groupinfo group1 [...]

Command-line options for yum

# No gpg check: No gpg check
 #- y: Automatically answer yes
 #- q: silent mode
 # -- disablerepo=repoidglob: temporarily disable the repo specified here
 # -- enablerepo=repoidglob: Temporarily enable the repo specified here
 # -- noplugins: Disable all plug-ins

Variables available in yum's repo configuration file

# releasever: The main version number of the current OS release;
# arch: Platform;
# basearch: Basic Platform;
# $YUM0-$YUM9

//For example:
# http://mirrors.magedu.com/centos/$releasever/$basearch/os

Create yum warehouse

Grammatical Format:

# createrepo [options] <directory>

Package Compilation and Installation

After installing testapp-VERSION-release.src.rpm-->, use rpmbuild command to make RPM package in binary format, and then install it again.

Overall process:

Source code - > preprocessing - > compilation (gcc) - - > assembly - > link - > execution

Source code organization format

Multi-file: There is probably a cross-file dependency between the codes in the file.

# C,C++:  make (configure --> Makefile.in --> makefile)
# java: maven

Three steps of C code compilation and installation

#1, ./configure: 
	(1) Pass parameters through options, specify enabling features, installation paths, etc. When executed, make files are generated by referring to user's designation and Makefile.in file.
   	(2) Check the dependent external environment
 
#2, make: 
    According to the makefile file file, build the application program;
    			
#3, make install

development tool

  • autoconf: Generating configure scripts
  • automake: Makefile.in

Recommendation: Check INSTALL, README before installation

Acquisition of Open Source Program Source Code

#1. Official self-built sites:
   	apache.org (ASF)
   	mariadb.org
   	...
#2. Code hosting:
   	SourceForge
   	Github.com
    code.google.com

Compile C source code

# c/c++: gcc (GNU C Complier)

Compilation Prerequisites

# Providing development tools and environment

	# Development tools: make, gcc, etc.
    # Development environment: development libraries, header files
    	glibc: Standard Library
	# Providing development components through "package groups"
    	CentOS 6: "Development Tools", "Server Platform Development",

Compilation steps

  • Step 1: configure script
Options: Specify installation location and enabled features

--help: Get the options it supports
	Options classification:
		Installation path setting:
			-- prefix=/PATH/TO/SOMEWHERE: Specify the default installation location; default is/usr/local/
			sysconfdir=/PATH/TO/SOMEWHERE: Configuration file installation location

		 System types:
		
		Optional Features: Optional Features
			--disable-FEATURE
			--enable-FEATURE[=ARG]

		Optional Packages: Optional Packages
			--with-PACKAGE[=ARG]
			--without-PACKAGE
  • Step 2: make
  • Step 3: make install

Configuration after installation

(1) Export binary program directory to PATH environment variable;
  	Edit the file/etc/profile.d/NAME.sh
		export PATH=/PATH/TO/BIN:$PATH

(2) Export library file path
	Edit/etc/ld.so.conf.d/NAME.conf
		Add the directory where the new library file is located to this file;

    Let the system regenerate the cache:
    	ldconfig [-v]

(3) Export header file
    Link-based implementation:
    	ln -sv 

(4) Export Help Manual
    Edit/etc/man.config file
    	Add a MANPATH

How to use CD-ROM as a local yum warehouse

(1) Mount a CD to a directory, such as/media/cdrom
	# mount -r -t iso9660 /dev/cdrom /media/cdrom
(2) create profile
	[CentOS7]
	name=
	baseurl=
	gpgcheck=
	enabled=

Posted by Walle on Sun, 28 Jul 2019 00:25:14 -0700