Use of yum tool

Use of yum tool

1. Disadvantages of rpm

We talked about rpm earlier, so what are the disadvantages of rpm? The disadvantages are obvious. When using rpm to install software, if you encounter software with dependencies, you must first install the dependent software before continuing to install the software we want to install. When the dependencies are very complex, this installation method It's a headache, so we need another installation method to solve this problem, today we are going to learn such a tool - yum

2. Advantages and disadvantages of yum

What are the advantages of yum? The biggest advantage of yum is that it can solve the dependency problem of rpm, and yum can automatically solve the dependencies of software installation.
Of course, there are advantages and disadvantages. No one is perfect, and the software is the same. The defect of yum is that if the installation process is forcibly terminated without completing the installation, the dependencies will not be resolved the next time you install. Fedora22+, redhat7 and centos7, etc. can solve this problem by manually installing the dnf tool.
dnf is a tool used to replace yum on redhat7. The meaning of its existence is to deal with the defects of yum, but its usage is exactly the same as yum, even the options are the same, you can understand that dnf is yum, just change Just a name. Therefore, as long as you learn yum, you will naturally know dnf. You don't have to worry about learning dnf after learning yum.

3. What is yum and what it does

So what is yum? yum is the abbreviation of yellowdog update manager, it can realize all the operations of rpm management, and can automatically resolve the dependencies between rpm packages. yum is a front-end tool for rpm and a tool for software management based on rpm.
You can't use yum to manage windows exe packages, and you can't use yum to manage ubuntu's deb packages, you can only use yum to manage redhat series rpm packages

4. Mount the CD

  • insert disc
  • Execute the following command
[root@zjq ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@zjq ~]# ls /mnt/
AppStream  BaseOS  EFI  images  isolinux  LICENSE  media.repo  TRANS.TBL

5. The principle of yum

The work of yum requires two parts to cooperate, one part is the yum server, and the other part is the yum tool of the client. The working principles of the two parts are described below.

How yum server works
All the rpm packages to be released are placed on the yum server for others to download. The rpm packages are compiled and released according to the version number of the kernel and the version number of the cpu. The yum server only needs to provide a simple download, either in the form of ftp or http. One of the most important aspects of the yum server is to sort out the basic information of each rpm package, including the version number corresponding to the rpm package, conf file, binary information, and critical dependency information. The createrepo tool is provided on the yum server, which is used to make a "list" of the basic summary information of the rpm package. This "list" is the information in the spec file describing each rpm package.

The working principle of the client side
Every time the client calls yum install or search, it will parse all the configuration files ending with .repo under /etc/yum.repos.d. These configuration files specify the address of the yum server. yum will regularly update the rpm package list on the yum server, and then download the list and save it to the yum client's own cache, according to the configuration in /etc/yum.conf (the default is /var/cache/yum), each time When calling yum to install the package, it will go to the cache directory to find the list, and determine the name, version number, required dependency packages, etc. of the installation package according to the rpm package description in the list, and then go to the yum server to download the rpm installation. (The premise is that there is no cache for the rpm package)

6. yum configuration file

  • What are the configuration files:
    • /etc/yum.conf role: provide common configuration for all repositories
    • /etc/yum.repos.d/*.repo role: provide configuration for the point of the warehouse
  • Variables available in yum's repo configuration file:
    • $releaseversion: The major version number of the current OS release
    • $arch: platform type
    • $basearch: base platform

Define the repo file for yum:

[Repo_Name]: warehouse name
name: Description
baseurl: The specific path of the warehouse, accepts the following three types
    ftp://
    http://
    file:///
enabled: optional value{1|0},1 To enable this repository, 0 to disable this repository
gpgcheck: optional value{1|0},1 In order to check the validity of the package source, 0 means not to check the source
    if gpgcheck Set to 1, you must use gpgkey Define the specific path of the key file
    gpgkey=/PATH/TO/KEY
vim /etc/yum.conf
cachedir=/var/cache/yum/$basearch/$releasever   //cache directory
keepcache=0     //Cache packages, 1 startup 0 shutdown
debuglevel=2    //debug level
logfile=/var/log/yum.log    //Logging location
exactarch=1     //Check if the platform is compatible
obsoletes=1     //Check package for obsolete
gpgcheck=1      //To check whether the source is legal, the public key information of the producer is required
plugins=1       //Whether to enable plugins
tolerant={1|0}  //Fault tolerance function, 1 is on, 0 is off, when set to 0, if you use yum to install multiple software packages and one of them has been installed, an error will be reported; when set to 1, when the software to be installed has been installed Automatically ignored when installing
installonly_limit=5
bugtracker_url
# metadata_expire=90m // Manually check metadata every hour
# in /etc/yum.repos.d //Contain repos.d directory 

7. yum warehouse management

7.1 yum local repository

  • Create a local yum file
[root@zjq ~]# cd /etc/yum.repos.d/
[root@zjq yum.repos.d]# vi base.repo 
  • Configure the repo file
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
gpgcheck=0
enabled=1
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
gpgcheck=0
enabled=1
  • Clear yum local cache
[root@zjq ~]# yum clean all
32 files removed
  • Check yum local repository
[root@zjq ~]# yum list all 

7.2 yum network warehouse

  • Official network yum warehouse (foreign)
  • Alibaba Cloud yum warehouse
  • 163yum warehouse
  • xx university yum warehouse
  • epel source
// Alibaba cloud centos 8 image
[root@zjq ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--       0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--       0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     100  2495  100  2495    0     0    981      0  0:00:02  0:00:02 --:--:--   981

//Delete cloud host configuration
[root@zjq ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//clear local cache
[root@zjq ~]# yum clean all
13 files removed

//Run yum makecache to generate the cache
[root@zjq ~]# yum makecache 
CentOS-8.5.2111 - Base - mirrors.aliyun.com  490 kB/s | 4.6 MB     00:09    
CentOS-8.5.2111 - Extras - mirrors.aliyun.co  30 kB/s |  10 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun 376 kB/s | 8.4 MB     00:22    
Metadata cache created.

7.3 Official software warehouse

// The source search method is basically the same, zabbix,mysql,saltstack,openstack, etc., go to the official website to find
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo 
baseurl=http://nginx.org/packages/centos/7/$basearch/ 
gpgcheck=0
enabled=1

7.4 redhat7 uses the yum source of centos7

//Download base and epel repositories
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# sed -i 's#\$releasever#7#g' /etc/yum.repos.d/CentOS-Base.repo

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

8. yum management software

8.1 yum command syntax:

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

8.2 Common options:

--nogpgcheck                //If downloading packages from the Internet sometimes checks gpgkey, you can use this command to skip the gpgkey check
-y                          //Automatically answer "yes"
-q                          //Silent mode, does not output information to standard output during installation
--disablerepo=repoidglob    //Temporarily disable the repo specified here
--enablerepo=repoidglob     //Temporarily enable the repo specified here
--noplugins                 //Disable all plugins

8.3 Common command s:

list            //list
    all         //default
    available   //List all available packages that are in the repository but not installed
    installed   //List installed packages
    updates     //Available upgrades
    
clean           //clear cache
    packages
    headers
    metadata
    dbcache
    all
    
//repolist //Display the list of repo and its brief information
    all
    enabled     //default
    disabled
[root@zjq ~]# dnf repolist 
repo id            repo name
AppStream          CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
base               CentOS-8.5.2111 - Base - mirrors.aliyun.com
extras             CentOS-8.5.2111 - Extras - mirrors.aliyun.com

    
//install //install
    yum install packages [...]
[root@zjq ~]# yum -y install vim
......
Installed:
  gpm-libs-1.20.7-17.el8.x86_64                                              
  vim-common-2:8.0.1763-16.el8.x86_64                                        
  vim-enhanced-2:8.0.1763-16.el8.x86_64                                      
  vim-filesystem-2:8.0.1763-16.el8.noarch                                    

Complete!

    
//update //upgrade
    yum update packages [...]
[root@zjq ~]# dnf -y update

//List packages that can be updated
[root@zjq ~]# dnf list updates 

update_to       //Upgrade to the specified version

downgrade package1 [package2 ...]   //downgrade

//remove|erase //Uninstall
[root@zjq ~]# yum -y remove vim
......
Removed:
  gpm-libs-1.20.7-17.el8.x86_64                                              
  vim-common-2:8.0.1763-16.el8.x86_64                                        
  vim-enhanced-2:8.0.1763-16.el8.x86_64                                      
  vim-filesystem-2:8.0.1763-16.el8.noarch                                    

Complete!


info    //show the result of rpm -qi package
    yum info packages
    
provides|whatprovides   //See which package installation generated the specified file or feature

//search string1 [string2 ...] //Search the package name and summary information with the specified keyword
[root@zjq ~]# dnf search wget
Last metadata expiration check: 0:42:25 ago on Mon 11 Jul 2022 02:59:52 PM CST.
======================== Name Exactly Matched: wget =========================
wget.x86_64 : A utility for retrieving files using the HTTP or FTP protocols

//deplist package [package2 ...] //Display the dependencies of the specified package
[root@zjq ~]# dnf deplist httpd
Last metadata expiration check: 0:44:21 ago on Mon 11 Jul 2022 02:59:52 PM CST.
package: httpd-2.4.37-41.module_el8.5.0+977+5653bbea.x86_64
  dependency: /bin/sh
   provider: bash-4.4.20-2.el8.x86_64
  dependency: /etc/mime.types
   provider: mailcap-2.1.48-3.el8.noarch
  dependency: httpd-filesystem
......

//history //View the historical transaction information of yum
[root@zjq ~]# dnf history 
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     3 | -y install vim           | 2022-07-11 13:01 | Install        |    4   
     2 | -y install bash-completi | 2022-07-05 09:23 | Install        |    5   
     1 |                          | 2022-06-27 19:17 | Install        |  378 EE

localinstall    //Install local rpm packages and automatically resolve dependencies

//grouplist // list available groups
[root@zjq ~]# dnf grouplist 
Last metadata expiration check: 5:11:06 ago on Mon 11 Jul 2022 04:24:06 PM CST.
Available Environment Groups:
   Server with GUI
   Server
   Workstation
   Custom Operating System
   Virtualization Host
Installed Environment Groups:
   Minimal Install
......

//groupinstall "group name" //Install a group of software
[root@zjq ~]# dnf groupinstall "Development Tools" -y
        
createrepo Order    //Create metadata information for yum repository
[root@zjq ~]# yum -y install createrepo 
[root@zjq ~]# createrepo [options] <directory>

8.4 Specific examples

8.4.1 Searching for packages
//List software available in depots
[root@zjq ~]# dnf list all

//do a fuzzy search
[root@zjq ~]# dnf list |grep ftp
ftp.x86_64                                             0.17-78.el8                                            AppStream 
lftp.i686                                              4.8.4-2.el8                                            AppStream 
lftp.x86_64                                            4.8.4-2.el8                                            AppStream 
lftp-scripts.noarch                                    4.8.4-2.el8                                            AppStream 
python3-requests-ftp.noarch                            0.3.1-11.el8                                           AppStream 
syslinux-tftpboot.noarch                               6.04-5.el8                                             base      
tftp.x86_64                                            5.2-24.el8                                             AppStream 
tftp-server.x86_64                                     5.2-24.el8                                             AppStream 
vsftpd.x86_64                                          3.0.3-34.el8                                           AppStream 

//List package details
[root@zjq ~]# dnf info ftp
Last metadata expiration check: 0:20:09 ago on Mon 11 Jul 2022 02:59:52 PM CST.
Available Packages
Name         : ftp
Version      : 0.17
Release      : 78.el8
Architecture : x86_64
Size         : 70 k
Source       : ftp-0.17-78.el8.src.rpm
Repository   : AppStream
Summary      : The standard UNIX FTP (File Transfer Protocol) client
URL          : ftp://ftp.linux.org.uk/pub/linux/Networking/netkit
License      : BSD with advertising
Description  : The ftp package provides the standard UNIX command-line FTP
             : (File Transfer Protocol) client.  FTP is a widely used
             : protocol for transferring files over the Internet and for
             : archiving files.
             : 
             : If your system is on a network, you should install ftp in
             : order to do file transfers.
standard UNIX command-line FTP (File Transfer Protocol) client. FTP is a widely used protocol for transferring files over the Internet and for archiving files.
: If your system is on a network, you should install ftp in order to do file transfers.

Tags: Linux Ubuntu server

Posted by derzok on Wed, 13 Jul 2022 00:58:21 +0930