Introduction to Linux basic commands 11: software package management

Time:2022-5-5

The management of software package in Linux varies with the system release version. Rpm and dpkg are the two most common software package management tools, which are applied to the Linux release based on RPM package and the Linux release based on DEB package respectively.
This article only describes the use of RPM. Another command is different, but the usage is similar, so I won’t introduce it.

1、rpmRPM package manager

option-qIndicates the software package installed in the query system

[[email protected] ~]# rpm -q sudo
sudo-1.8.6p7-16.el7.x86_64
[[email protected] ~]# rpm -q nginx
Package nginx is not installed 
[[email protected] ~]#

option-aIndicates to query all installed RPM packages

[[email protected] ~]# rpm -qa|grep vim
vim-filesystem-7.4.160-1.el7.x86_64
vim-common-7.4.160-1.el7.x86_64
vim-enhanced-7.4.160-1.el7.x86_64
vim-minimal-7.4.160-1.el7.x86_64
[[email protected] ~]#

option-f fileIndicates the package to which the query file belongs

[[email protected] ~]# rpm -qf /usr/bin/ls
coreutils-8.22-15.el7.x86_64
[[email protected] ~]#

option-cRepresents the configuration file of the query package

[[email protected] ~]# rpm -qc sudo
/etc/pam.d/sudo
/etc/pam.d/sudo-i
/etc/sudo-ldap.conf
/etc/sudo.conf
/etc/sudoers
[[email protected] ~]#

option-eIndicates uninstalling the package

[[email protected] ~]# rpm -e sudo
Warning: / etc / sudoers has been saved as / etc / sudoers rpmsave
[[email protected] ~]# rpm -q sudo
Package sudo is not installed 
[[email protected] ~]#

option-iIndicates installation-vIndicates display details-hIndicates that the installation progress is displayed

#Download RPM package
[[email protected] tmp]# wget ftp.scientificlinux.org/linux/scientific/7rolling/x86_64/os/Packages/sudo-1.8.6p7-16.el7.x86_64.rpm
#Installation
[[email protected] tmp]# rpm -ivh sudo-1.8.6p7-16.el7.x86_64.rpm 
Warning: sudo-1.8.6p7-16 el7. x86_ 64. RPM: header V4 DSA / SHA1 signature, key ID 192a7d7d: nokey
In preparation################################# [100%]
Upgrading / installing
   1:sudo-1.8.6p7-16.el7              ################################# [100%]

There are many software packages that do not have only one RPM package. There are various dependencies between them. When installing (or uninstalling), you need to install (or uninstall) all the dependent packages before you can install (or uninstall) successfully

[[email protected] tmp]# rpm -e vim-common
Error: dependency detection failed:
    vim-common = 2:7.4.160-1. EL7 (installed) vim-enhanced-2: 7.4.160-1 el7. x86_ 64 required

option--nodepsIndicates ignoring dependencies

[[email protected] tmp]# rpm -q vim-common
vim-common-7.4.160-1.el7.x86_64
[[email protected] tmp]# rpm -e --nodeps vim-common
Warning: / etc / vimrc has been saved as / etc / vimrc rpmsave
[[email protected] tmp]# rpm -q vim-common
Package VIM common is not installed

option-UIndicates a software package upgrade

[[email protected] tmp]# rpm -q wget
wget-1.14-10.el7_0.1.x86_64
[[email protected] tmp]# rpm -Uvh wget-1.14-13.el7.x86_64.rpm 
In preparation################################# [100%]
Upgrading / installing
   1:wget-1.14-13.el7                 ################################# [ 50%]
Cleaning up / deleting
   2:wget-1.14-10.el7_0.1             ################################# [100%]
[[email protected] tmp]# rpm -q wget
wget-1.14-13.el7.x86_64

2、yumDownload Updater

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

yumIs an interactive package manager based on RPM. When installing the software, yum does not need to manually find the installation like rpm. When it works, it will search the RPM package in the source, automatically solve the dependencies, and automatically download and install. The yum default source profile is located in the directory/etc/yum.repos.dInside.
commandinstallIndicates installation

[[email protected] ~]# yum install vim-common
Plugin: fastmirror loaded
Loading mirror speeds from cached hostfile
 * base: mirrors.yun-idc.com
 * extras: mirrors.yun-idc.com
 * updates: mirrors.yun-idc.com
Resolving dependencies
-->Checking transactions
--->Package VIM common x86_ 64.2.7.4.160-1. EL7 will be installed
-->Resolve dependency complete

Dependency resolution
# Omit partial output
Install 1 package

Total downloads: 5.9 M
Installation size: 21 M
Is this OK [y / D / N]: y # need to enter here to confirm whether to install
Downloading packages:
vim-common-7.4.160-1.el7.x86_64.rpm                         | 5.9 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: the RPM database has been modified by a non Yum program.
**An existing RPM database problem was found. The 'Yum check' output is as follows:
2:vim-enhanced-7.4.160-1. el7. x86_ 64 there are missing requirements VIM common = ('2', '7.4.160', '1. EL7')
  Installing: 2: vim-common-7.4.160-1 el7. x86_ 64                         1/1 
  Verification in progress: 2: vim-common-7.4.160-1 el7. x86_ 64                         1/1 

Installed:
  vim-common.x86_64 2:7.4.160-1.el7                                                                                                   

complete!

commandcheck-updateIndicates check for updates
commandupdateIndicates an upgrade
commandsearchRepresents a search package
commandlistIndicates that the available packages are listed
commandremoveIndicates uninstall
commandcleanIndicates that the contents of the yum cache directory are cleared
option-yIndicates that yes is entered by default in all places requiring interactive confirmation
WhenyumWhen there is no package to be installed in the source, an error will be reportedNo packages availableError. You can solve this problem by adding a new Yum source
If nginx is installed in CentOS 7:

#Install repo
[[email protected] tmp]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
obtain http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Warning: / var / TMP / RPM TMP Uanoe: header V4 RSA / SHA1 signature, key ID 7bd9bf62: nokey
In preparation################################# [100%]
Upgrading / installing
   1:nginx-release-centos-7-0.el7.ngx ################################# [100%]

At this time, / etc / yum.com repos. D added a new file nginx repo

[[email protected] tmp]# cat /etc/yum.repos.d/nginx.repo 
# nginx.repo

[nginx]
Name = nginx repos # name
baseurl= http://nginx.org/packages/centos/7/ $basearch / # source address
Gpgcheck = 0 # whether to check the key. 0 means not to check
Enabled = 1 # where 0 means baseurl is not enabled, and 1 means baseurl is enabled

Now you can pass the commandyum install -y nginxNginx installed
When the server has no network available, you can also set the local Yum source. At this point, you need to manually configure the repo file
First, mount the installation CD or IOS file to the system (for more information about mounting, please seeThis one)

[[email protected] tmp]# mount CentOS-7-x86_64-DVD-1611.iso /media
Mount: / dev / loop2 is write protected and will be mounted read-only
[[email protected] tmp]# 
#If it is a CD, mount it as follows:
[[email protected] tmp]# mount /dev/cdrom /media
Mount: / dev / sr0 is write protected and will be mounted as read-only
[[email protected] tmp]#
#Unmount with umount or eject
[[email protected] tmp]# umount /media
[[email protected] tmp]# eject

Edit Yum source profile

vim /etc/yum.repos.d/local.repo
    [local]
    name=test
    baseurl= file:///media #Here, write the prefix of baseurl (file: //) + mount point
    enabled=1
    gpgcheck=0

Then back up the original network source configuration file to another directory, / etc / yum repo. Only local is reserved in D Repo file. Install software:

yum install bc -y

3. Source package

RPM and DEB mentioned above are binary packages. Since these packages have been compiled, users cannot set compilation options or make any changes to the software. Relatively speaking, compiling and installing software using the source package provides more flexibility. Various options can be specified during compilation. For capable users, the source code can also be modified. Here’s how to install the source package in Linux

1. Get source package

wget http://mirrors.sohu.com/nginx/nginx-1.9.6.tar.gz

2. Decompress

tar zxf nginx-1.9.6.tar.gz

3. Disposition

[[email protected] src]# cd nginx-1.9.6
[[email protected] nginx-1.9.6]# ./configure --prefix=/usr/local/nginx

Configure options here--prefix=/usr/local/nginxIndicates that the installation path of the specified nginx is / usr / local / nginx.
Can execute./configure --helpCheck the configuration parameters. The execution of this step will check whether the system meets the compilation requirements. If an error is reported, in many cases it is because some compilation tools are missing. You can use Yum to install these tools (of course, you can also install the source code).
In this case, an error is reported:./configure: error: the HTTP rewrite module requires the PCRE library.
Note: the PCRE library is missing. Check the system:

[[email protected] nginx-1.9.6]# rpm -qa pcre
pcre-8.32-15.el7.x86_64
[[email protected] nginx-1.9.6]#

PCRE is installed on the system, but there is no devel package. Use Yum to install

[[email protected] nginx-1.9.6]# yum install pcre-devel -y

Execute configure again and find that the error is changed:./configure: error: the HTTP gzip module requires the zlib library.
Repeat the above operation until the required software is installed, and then perform it again./configure --prefix=/usr/local/nginx

4. Compile

[[email protected] nginx-1.9.6]# make -j8

usemakeCompile, options-jIndicates the specified number of concurrent executions. Here, the number of and system logical CPUs is specified (you can use the command)grep -c "^processor" /proc/cpuinfoView the same number of concurrent logical CPUs.
Errors may also occur in this step, which is generally due to the lack of packages. It is generally not difficult to solve by carefully reading the error information.

5. Installation

[[email protected] nginx-1.9.6]# make install

If there are no errors, the package will be installed. You can find the installed files in / usr / local / nginx.

Here is the general installation process of the source package. The installation of some source packages may be different. Generally, there are corresponding installation instructions in the source package(READMEorINSTALL), read these files carefully or check the official website of the software to find their installation methods.