Software package installation and uninstallation

Keywords: Operation & Maintenance yum RPM CentOS vim

Package Installation and Unloading

1. Three ways to install software packages

rpm package

yum tool

Source package

2. rpm package introduction

RPM tools are similar to Windows exe files, which can be installed directly, and the installation path and file name are generally fixed. Installation packages under CentOS and Red Hat are generally referred to as RPM packages. yum is a tool developed in Python. Compared with rpm, yum has one advantage: it can automatically install dependent packages. Source packages need to compile their own source code into binary executable files, so source packages are the most troublesome.

  • The CD-ROM drive of the virtual machine can be connected properly and put into an iso image file.

  • Mount CD-ROM

[root@sc ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 Write protection will be mounted as read-only
  • cd into / mnt / directory, you can see the files in the cd-ROM drive

  • There are many RPM packages in the Packages / directory. Let's take a look at the format of these rpm packages.
[root@sc mnt]# cd Packages/
[root@sc Packages]# ls        

3. Use of RPM tools

  • rpm-ivh is the instructions for installing rpm packages
[root@sc Packages]# rpm -ivh zsh-5.0.2-31.el7.x86_64.rpm 
In preparation...
Upgrading/Installing...
   1:zsh-5.0.2-31.el7                 ################################# [100%]
[root@sc Packages]# 
  • rpm-Uvh is the instruction to upgrade rpm packages
[root@sc Packages]# rpm -Uvh zsh-5.0.2-31.el7.x86_64.rpm 
In preparation...
	The package zsh-5.0.2-31.el7.x86_64 has been installed
[root@sc Packages]# 
  • rpm-e is an instruction to uninstall rpm packages
[root@sc Packages]# rpm -e zsh
[root@sc Packages]# 
  • Rpm-qa is a query for packages installed by rpm
[root@sc Packages]# rpm -qa
firewalld-filesystem-0.5.3-5.el7.noarch
grub2-common-2.02-0.76.el7.centos.noarch
kbd-1.15.5-15.el7.x86_64
kbd-legacy-1.15.5-15.el7.noarch
tuned-2.10.0-6.el7.noarch
tzdata-2018e-3.el7.noarch
. . . . . 
  • Rpm-q "package name" to query whether the specified package is installed
[root@sc Packages]# rpm -q gpgme
gpgme-1.3.2-5.el7.x86_64
[root@sc Packages]# 
  • Rpm-qi "package name" to query specified package information
[root@sc Packages]# rpm -qi vim-enhanced 
Name        : vim-enhanced
Epoch       : 2
Version     : 7.4.160
Release     : 5.el7
Architecture: x86_64
Install Date: 2019year03month23Sunday and Saturday 22time56branch02second
Group       : Applications/Editors
Size        : 2296666
License     : Vim
Signature   : RSA/SHA256, 2018year11month12Sunday, Monday 22time48branch44second, Key ID 24c6a8a7f4a80eb5
Source RPM  : vim-7.4.160-5.el7.src.rpm
Build Date  : 2018year10month31Wednesday, Sunday 03time57branch29second
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.vim.org/
Summary     : A version of the VIM editor which includes recent enhancements
Description :
VIM (VIsual editor iMproved) is an updated and improved version of the
vi editor.  Vi was the first real screen-based editor for UNIX, and is
still very popular.  VIM improves on vi by adding new features:
multiple windows, multi-level undo, block highlighting and more.  The
vim-enhanced package contains a version of VIM with extra, recently
introduced features like Python and Perl interpreters.

Install the vim-enhanced package if you'd like to use a version of the
VIM editor which includes recently added enhancements like
interpreters for the Python and Perl scripting languages.  You'll also
need to install the vim-common package.
  • Rpm-ql "package name" lists the files installed by the package
[root@sc Packages]# rpm -ql vim-enhanced 
/etc/profile.d/vim.csh
/etc/profile.d/vim.sh
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor
[root@sc Packages]# 
  • Rpm-qf "package name", viewing a file according to its absolute path is installed by that package
[root@sc Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-5.el7.x86_64
[root@sc Packages]# 

4. Usage of Yum tools

yum (all called Yellow Dog Updater, Modified) is a Shell front-end package manager in Fedora, Red Hat and CentOS. Based on RPM package management, RPM packages can be downloaded and installed automatically from designated servers, dependency relationships can be handled automatically, and all dependent packages can be installed at one time, without tedious downloading and installation. yum provides commands to find, install, and delete one, group, or even all packages, and the commands are concise and memorable.

  • When installing rpm packages with yum, it can automatically install dependent packages, and only need to write the package name.
[root@sc Packages]# yum install texlive

As can be seen from the figure above, there are more than 200 dependent packages. If you install them with rpm packages, you have to install them one by one. It is estimated that no one has the patience and time to install more than 200 packages manually. So the biggest advantage of yum tool is that it can install dependent packages automatically here.

  • Use the yum list command to list available rpm packages
[root@sc Packages]# yum list  #List all packages that can be installed.

  • Look at the configuration file of the yum repository, which has many core files
[root@sc Packages]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@sc Packages]# ls /etc/yum.repos.d/CentOS-Base.repo  #View the core files
[root@sc Packages]# cat /etc/yum.repos.d/CentOS-Base.repo

  • yum search, search for "instructions" and related packages
[root@sc Packages]# yum search vim  #This command search is vague and lists all the packages of vim-related commands.
//Loaded plug-in: fastest mirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
============================================================================ 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 profile match only, try "search all".
  • Search for command-related packages more accurately from listed packages

  • Use the yum tool to install rpm packages, and do not want to be asked to add-y
[root@sc Packages]# yum install -y vim -enhanced  #Don't want to be questioned -y
  • yum grouplist lists available groups
[root@sc Packages]# yum grouplist
 Loaded plug-in: fastest mirror
 No Group Information File Installed
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.zju.edu.cn
 * extras: mirror.jdcloud.com
 * updates: mirror.jdcloud.com
 Available environment grouping:
   minimal installation
   Infrastructure Server
   Computational Node
   File and Print Server
   Basic Web Server
   Virtualization host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and generation of workstations
 Available groups:
   Traditional UNIX Compatibility
   Compatibility Library
   Graphics Management Tool
   Security tools
   development tool
   Console Internet Tools
   Smart Card Support
   Scientific Numbering Support
   system management
   system management tool
 complete
 [root@sc Packages]# LANG=en # becomes English
 [root@sc Packages]# yum grouplist # Look at the listed groups again
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
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
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done
  • Yum group install can install an available group
[root@sc Packages]# yum groupinstall 'Virtualization Host'  #Install a group without any characters if it is a word and single quotation marks if there is a space in the full name. 

  • yum Unloading Pack
[root@sc Packages]# yum remove vim

  • yum update update upgrade instructions, followed by package name, if not, will upgrade all rpm packages, including the system, the kernel, this operation is often just installed to operate, if some services have been installed, build some environment, do not upgrade at will, may be a problem.
[root@sc Packages]# yum update  #After adding the package name, without the package name will upgrade the system, the kernel, very dangerous!!!
  • To retrieve the rpm package of a command, for example, I need to retrieve the rpm package of vim command, provided that VIM package has not been installed, I do not know the full package name, find two identical, or many identical, then it must be the package name.
[root@sc Packages]# yum provides "/*/vim"
perhaps
[root@sc ~]# yum provides */vim  #You can also search for package names according to instructions

5. yum Builds Local Warehouse

Handout

• Mount the image to/mnt Catalog
• cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
• rm -f /etc/yum.repos.d/*
• vim /etc/yum.repos.d/dvd.repo //The contents are as follows

[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpgcheck=0

• yum clean all
• yum list

Because yum needs to connect a resource to download and retrieve rpm packages, building local libraries can prevent the absence of networks, or install some packages through local libraries.

Ideas for configuring local warehouses:
1. It is necessary to load the iso image of centos7 into the reverse CD-ROM drive and mount the CD-ROM into the / mnt directory for viewing.
2. We need to copy the yum source warehouse configuration file of the previous computer, and the warehouse configuration file is in / etc/yum.repo/.
3. Delete the source warehouse configuration file;
4. Create a new dvd.repo warehouse file and write the configuration file.
5. Use yum clear all to clear the cache of yum source;
6. After that, the local yum source can be used.

  • Prepare a mirror file to mount in the / mnt directory, backup / etc/yum.repos.d / this directory is / etc/yum.repos.d.bak
[root@sc Packages]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak
[root@sc Packages]# 
  • Delete all files in / etc/yum.repos.d / directory
[root@sc Packages]# cd /etc/yum.repos.d
[root@sc yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo  CentOS-fasttrack.repo
[root@sc yum.repos.d]# rm -fr ./*
[root@sc yum.repos.d]# 
  • Create a dvd.repo file in / etc/yum.repos.d / directory and write the following in the dvd.repo file
[root@sc yum.repos.d]# vi dvd.repo

[dvd]
name=install dvd        #Notes
baseurl=file:///mnt
enable=1                #Whether the source is available,1Represents available,0Indicates unavailability
gpgcheck=0              #Whether to detect,0Represents non-detection
  • Clear the cache in the yum repository before
[root@sc yum.repos.d]# yum clean all     #Clear Cache
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Cleaning repos: dvd
Other repos take up 138 M of disk space (use --verbose for details)
  • List packages for local warehouses
[root@sc yum.repos.d]# yum list
[root@sc yum.repos.d]# yum list |less  #Take a look at the pipeline with less

  • Experiments, try to install the package GConf2.x86_64 3.2.6-8.el7 dvd of the local warehouse
[root@sc yum.repos.d]# yum install GConf2
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package GConf2.x86_64 0:3.2.6-8.el7 will be installed
--> Processing Dependency: /usr/bin/killall for package: GConf2-3.2.6-8.el7.x86_64
--> Running transaction check
---> Package psmisc.x86_64 0:22.20-15.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================
 Package  Arch     Version           Repository
                                            Size
=================================================
Installing:
 GConf2   x86_64   3.2.6-8.el7       dvd   1.0 M
Installing for dependencies:
 psmisc   x86_64   22.20-15.el7      dvd   141 k

Transaction Summary
=================================================
Install  1 Package (+1 Dependent package)

Total download size: 1.1 M
Installed size: 6.8 M
Is this ok [y/d/N]: y
Downloading packages:
-------------------------------------------------
Total               3.2 MB/s | 1.1 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : psmisc-22.20-15.el7.x86_64    1/2 
  Installing : GConf2-3.2.6-8.el7.x86_64     2/2 
  Verifying  : psmisc-22.20-15.el7.x86_64    1/2 
  Verifying  : GConf2-3.2.6-8.el7.x86_64     2/2 

Installed:
  GConf2.x86_64 0:3.2.6-8.el7                    

Dependency Installed:
  psmisc.x86_64 0:22.20-15.el7                   

Complete!

6. yum Replacement of Domestic Sources

CentOS has its own yum warehouse source web site is a foreign web site, so it is sometimes slow or impossible to download rpm packages from domestic websites. At this time, it is possible to replace the domestic yum warehouse source to solve this problem.

  • Delete the dvd.repo file in the / etc/yum.repos.d directory (you don't need to do this if you haven't created a local source repository)
[root@sc Packages]# cd /etc/yum.repos.d
[root@sc yum.repos.d]# ls
dvd.repo
[root@sc yum.repos.d]# rm -fr dvd.repo 
[root@sc yum.repos.d]# ls
[root@sc yum.repos.d]# 
  • Copy back the previous / yum.repos.d.bak file in / etc / backup (you don't need to do this if you haven't created a local source repository)
[root@sc yum.repos.d]# cp ../yum.repos.d.bak/* .
[root@sc yum.repos.d]# ls
CentOS-Base.repo       CentOS-Media.repo
CentOS-CR.repo         CentOS-Sources.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo
CentOS-fasttrack.repo
[root@sc yum.repos.d]# 
[root@sc yum.repos.d]# rm -f CentOS-Base.repo  #Delete the previous source file
[root@sc yum.repos.d]# ls
CentOS-CR.repo         CentOS-Media.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo
CentOS-fasttrack.repo  CentOS-Vault.repo
  • Use the wget command or curl command to download the 163 source or aliyuan, because I deleted the CentOS-Base.repo file in the previous step, so I can only use curl command.

163 domestic sources or aliyuan:

Note: Just deleted the foreign source, so yum can't wget this command
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

Note: You can only use curl-O to install the yum source
curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
curl -O http://mirrors.aliyun.com/repo/Centos-7.repo

[root@sc yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1572  100  1572    0     0  16618      0 --:--:-- --:--:-- --:--:-- 16723
[root@sc yum.repos.d]# ls
CentOS7-Base-163.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo

[root@sc yum.repos.d]# vim CentOS7-Base-163.repo

Finally, you can use yum list to see the available rpm packages.

[root@sc yum.repos.d]# yum install -y zsh
 Loaded plug-in: fastest mirror
Loading mirror speeds from cached hostfile
 Resolving dependencies
 --> Inspecting business
 The package zsh.x86_64.0.5.0.2-31.el7 will be installed
 --> Resolving Dependency Completion

Dependency Resolution

=================================================
 Package
        Architecture version source size
=================================================
Installing:
 zsh    x86_64    5.0.2-31.el7     base    2.4 M

Transaction summary
=================================================
Install 1 package

Total download: 2.4M
 Installation Size: 5.6M
Downloading packages:
zsh-5.0.2-31.el7.x86_64.rpm | 2.4 MB   00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installation in progress: zsh-5.0.2-31.el7.x86_64 1/1 
  Verification: zsh-5.0.2-31.el7.x86_641/1 

Installed:
  zsh.x86_64 0:5.0.2-31.el7                      

Complete!
  • Install the wget command
[root@sc yum.repos.d]# yum install -y wget
 Loaded plug-in: fastest mirror
Loading mirror speeds from cached hostfile
 Resolving dependencies
 --> Inspecting business
 The package wget.x86_64.0.1.14-18.el7 will be installed
 --> Resolving Dependency Completion

Dependency Resolution

=================================================
 Package Architecture Version Source Size
=================================================
Installing:
 wget    x86_64    1.14-18.el7     base    547 k

Transaction summary
=================================================
Install 1 package

Total download: 547 k
 Installation Size: 2.0M
Downloading packages:
wget-1.14-18.el7.x86_64.rpm | 547 kB   00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installation in progress: wget-1.14-18.el7.x86_64 1/1 
  Verification: wget-1.14-18.el7.x86_64 1/1 

Installed:
  wget.x86_64 0:1.14-18.el7                      

Complete!

7. Install the extended source epel

Since there is only a 163 base yum source, there may be some rpm packages that are not available in the warehouse, and an extension source needs to be installed to download some rpm packages that are not available in the warehouse.

  • Install epel-release extension source
[root@sc yum.repos.d]# yum install -y epel-release
 Loaded plug-in: fastest mirror
Loading mirror speeds from cached hostfile
 Resolving dependencies
 --> Inspecting business
 - > The package epel-release.noarch.0.7-11 will be installed
 --> Resolving Dependency Completion

Dependency Resolution

===========================================================================================================================================================================
 Package Architecture Version Source Size
===========================================================================================================================================================================
Installing:
 epel-release                                  noarch                                  7-11                                  extras                                   15 k

Transaction summary
===========================================================================================================================================================================
Install 1 package

Total download: 15 k
 Installation size: 24 k
Downloading packages:
epel-release-7-11.noarch.rpm                                                                                                                        |  15 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installation in progress: epel-release-7-11.noarch 1/1 
  Verification: epel-release-7-11.noarch 1/1 

Installed:
  epel-release.noarch 0:7-11                                                                                                                                               

Complete!
[root@sc yum.repos.d]# ls  #Now there are 9 A file.
CentOS7-Base-163.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel-testing.repo
CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo


[root@sc yum.repos.d]# cat epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
  • Using yum list to list available rpm packages, you will find that packages have increased a lot, and you can use grep filter to see more intuitive

8. yum downloads rpm packages

  • Because the RPM packages in the local Yum repository are limited, many RPM packages need to be downloaded on the network. But I want to download the RPM package locally. Next time we use it, we don't need to download it on the network. So we need to download the RPM package locally with yum. When downloading the rpm package, we need to make sure that the package has not been downloaded, otherwise the system will prompt that it has been downloaded.

  • After viewing the download, store the path of the rpm package

ls /var/cache/yum/x86_64/7/base/packages/

  • When downloading rpm packages, you can specify the storage path of RPM by downloaddir, such as I put it in the tmp directory

yum install zsh --downloadonly --downloaddir=/tmp/

  • If the rpm package you want to download is installed, the following prompts will appear

  • If you need to download the installed rpm package, you can use the reinstall command

yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/

9. yum's new instructions for downloading rpm

In the production environment, sometimes if we encounter such situations as banks, which only have an intranet and no external network, the operation and maintenance personnel need to download the package to the U disk first, and then install it into the server.

  • Install the yum-utils plug-in
[root@sc ~]# yum install -y yum-utils
  • Use the command yumdownloader to download rpm packages locally

  • If you download an RPM package on the official website and download it to the linux machine, if you want to install the command rpm-ivh, you can also install it with the yum command.

The advantage of this is that if the downloaded package has other dependent packages, yum can download other rpm packages automatically directly from the source repository

[root@sc tmp]# yum localinstall zsh-5.0.2-31.el7.x86_64.rpm

10. Extension

  1. yum keeps installed packages http://www.360doc.com/content/11/0218/15/4171006_94080041.shtml
  2. Building yum source of local area network https://blog.csdn.net/miouqi/article/details/73159297
  3. Build a yum source of http in local area network http://blog.lishiming.net/?p=500

Posted by ramjai on Thu, 18 Jul 2019 22:35:40 -0700