4-yum Tool Usage

Posted by playa4real on Mon, 09 Sep 2019 08:50:45 +0200

Yum is more convenient than rpm. The biggest advantage of the yum tool is that it can download the required RPM packages online and install them automatically. If the RPM packages to be installed depend on each other, the yum tool will help us install all the relevant RPM packages in turn

List all available rpm installation packages

[root@evan-01 ~]# yum list 
...(A lot of content is omitted.
zenity.x86_64                                                          3.28.1-1.el7                                        base     
zlib.i686                                                              1.2.7-18.el7                                        base     
zlib.x86_64                                                            1.2.7-18.el7                                        base     
zlib-devel.i686                                                        1.2.7-18.el7                                        base     
zlib-devel.x86_64                                                      1.2.7-18.el7                                        base     
zlib-static.i686                                                       1.2.7-18.el7                                        base     
zlib-static.x86_64                                                     1.2.7-18.el7                                        base     
zsh.x86_64                                                             5.0.2-31.el7                                        base     
zsh-html.x86_64                                                        5.0.2-31.el7                                        base     
zziplib.i686                                                           0.13.62-9.el7                                       base     
zziplib.x86_64                                                         0.13.62-9.el7                                       base     
zziplib-devel.i686                                                     0.13.62-9.el7                                       base     
zziplib-devel.x86_64                                                   0.13.62-9.el7                                       base     
zziplib-utils.x86_64                                                   0.13.62-9.el7                                       base     
[root@evan-01 ~]#

Take this as an example and say what it means.

zziplib-utils.x86_64     0.13.62-9.el7         base 
rpm package name Version information Installation information
zziplib-utils.x86_64 0.13.62.9.el7 base

If not installed, display base or anaconda; if rpm packages are installed but need to be upgraded, display updates

View the repository in the yum configuration file

[root@evan-01 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@evan-01 ~]# 
[root@evan-01 ~]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[root@evan-01 ~]# 

Search for rpm packages

[root@evan-01 ~]# yum search vim
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
========================================================= N/S matched: vim =========================================================
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor

  Name and summary matches only, use "search all" for everything.
[root@evan-01 ~]# 

These vim-related packages can be found, and this method is not accurate enough.

We can use grep to filter and find the corresponding rpm package

[root@evan-01 ~]# yum list | grep 'vim'
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
vim-common.x86_64                           2:7.4.160-6.el7_6          @updates 
vim-enhanced.x86_64                         2:7.4.160-6.el7_6          @updates 
vim-filesystem.x86_64                       2:7.4.160-6.el7_6          @updates 
vim-minimal.x86_64                          2:7.4.160-2.el7            @anaconda
protobuf-vim.x86_64                         2.5.0-8.el7                base     
vim-X11.x86_64                              2:7.4.160-6.el7_6          updates  
vim-minimal.x86_64
[root@evan-01 ~]# 

Install rpm packages
In the whole process, it lists the rpm packages that need to be installed first, and if there are dependencies, it lists all the dependent packages. Then ask the user if they need to install, enter y to install, and enter n to not install. That would be too cumbersome, so add the - y option directly, which omits the step of asking the user whether to install it or not.

[root@evan-01 ~]# yum install -y protobuf-vim
Loaded plugins: fastestmirror
base                                                                                                         | 3.6 kB  00:00:00     
extras                                                                                                       | 3.4 kB  00:00:00     
updates                                                                                                      | 3.4 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package protobuf-vim.x86_64 0:2.5.0-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                            Arch                         Version                           Repository                  Size
====================================================================================================================================
Installing:
 protobuf-vim                       x86_64                       2.5.0-8.el7                       base                       8.7 k

Transaction Summary
====================================================================================================================================
Install  1 Package

Total download size: 8.7 k
Installed size: 3.7 k
Downloading packages:
protobuf-vim-2.5.0-8.el7.x86_64.rpm                                                                          | 8.7 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : protobuf-vim-2.5.0-8.el7.x86_64                                                                                  1/1 
  Verifying  : protobuf-vim-2.5.0-8.el7.x86_64                                                                                  1/1 

Installed:
  protobuf-vim.x86_64 0:2.5.0-8.el7                                                                                                 

Complete!
[root@evan-01 ~]# 

Unloading rpm package
Like installation, Uninstall can add the - y option directly, thus omitting the step of interaction with the user. When uninstalling a rpm package, it must be clear that not even other important RPM packages are uninstalled, so as not to affect normal business, so when using yum remove command to uninstall the package, it is not necessary to add the - y option.

[root@evan-01 ~]# yum remove  protobuf-vim
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package protobuf-vim.x86_64 0:2.5.0-8.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                           Arch                        Version                             Repository                  Size
====================================================================================================================================
Removing:
 protobuf-vim                      x86_64                      2.5.0-8.el7                         @base                      3.7 k

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

Installed size: 3.7 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : protobuf-vim-2.5.0-8.el7.x86_64                                                                                  1/1 
  Verifying  : protobuf-vim-2.5.0-8.el7.x86_64                                                                                  1/1 

Removed:
  protobuf-vim.x86_64 0:2.5.0-8.el7                                                                                                 

Complete!
[root@evan-01 ~]# 

Upgrade rpm package
If no package name is added, all rpm packages in the system will be upgraded

[root@evan-01 ~]# yum update bash
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package bash.x86_64 0:4.2.46-28.el7 will be updated
---> Package bash.x86_64 0:4.2.46-31.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                     Arch                          Version                                Repository                   Size
====================================================================================================================================
Updating:
 bash                        x86_64                        4.2.46-31.el7                          base                        1.0 M

Transaction Summary
====================================================================================================================================
Upgrade  1 Package

Total download size: 1.0 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
bash-4.2.46-31.el7.x86_64.rpm                                                                                | 1.0 MB  00:00:12     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : bash-4.2.46-31.el7.x86_64                                                                                        1/2 
  Cleanup    : bash-4.2.46-28.el7.x86_64                                                                                        2/2 
  Verifying  : bash-4.2.46-31.el7.x86_64                                                                                        1/2 
  Verifying  : bash-4.2.46-28.el7.x86_64                                                                                        2/2 

Updated:
  bash.x86_64 0:4.2.46-31.el7                                                                                                       

Complete!
[root@evan-01 ~]# 

Which package does the search order have?
For example, if you want to install VIM packages, but you don't know the name of vim packages in yum, then we can use the command Yum provides'/*/vim'to search for them.

[root@evan-01 ~]# yum provides '/*/vim'
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
base/7/x86_64/filelists_db                                                                                   | 7.1 MB  00:00:45     
extras/7/x86_64/filelists_db                                                                                 | 249 kB  00:00:00     
http://mirrors.aliyun.com/centos/7.6.1810/updates/x86_64/repodata/a162eee98ea1692e6a955abb497dc7a487cd7bb9408bd170165949f9776d32fe-filelists.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyun.com/centos/7.6.1810/updates/x86_64/repodata/a162eee98ea1692e6a955abb497dc7a487cd7bb9408bd170165949f9776d32fe-filelists.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
updates/7/x86_64/filelists_db                                                                                | 5.2 MB  00:00:52     
cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system
Repo        : base
Matched from:
Filename    : /usr/share/cmake/editors/vim



git-1.8.3.1-19.el7.x86_64 : Fast Version Control System
Repo        : base
Matched from:
Filename    : /usr/share/doc/git-1.8.3.1/contrib/vim



git-1.8.3.1-20.el7.x86_64 : Fast Version Control System
Repo        : updates
Matched from:
Filename    : /usr/share/doc/git-1.8.3.1/contrib/vim



2:vim-common-7.4.160-5.el7.x86_64 : The common files needed by any version of the VIM editor
Repo        : base
Matched from:
Filename    : /usr/share/vim



2:vim-common-7.4.160-6.el7_6.x86_64 : The common files needed by any version of the VIM editor
Repo        : updates
Matched from:
Filename    : /usr/share/vim



2:vim-enhanced-7.4.160-5.el7.x86_64 : A version of the VIM editor which includes recent enhancements
Repo        : base
Matched from:
Filename    : /usr/bin/vim



2:vim-enhanced-7.4.160-6.el7_6.x86_64 : A version of the VIM editor which includes recent enhancements
Repo        : updates
Matched from:
Filename    : /usr/bin/vim



2:vim-enhanced-7.4.160-6.el7_6.x86_64 : A version of the VIM editor which includes recent enhancements
Repo        : @updates
Matched from:
Filename    : /usr/bin/vim



[root@evan-01 ~]#

Topics: vim CentOS RPM yum