Linux installation and management program-RPM and yum learn to install software super detailed


After the Linux operating system is installed in the host, it has the basis for software services, network services and other functions. However, after all, the software packages installed with the operating system are only a few, and the realized functions are also relatively limited. When it is necessary to provide more functions for the host, installing new applications becomes an inevitable task. Here's how to install and manage applications on Linux systems.

1. Query RPM package information

The RPM package is one of the most widely used software packages in various Linux hairstyle versions. With its powerful functions and wide compatibility, RPM packages are supported by most Linux distributions and supported by the majority of Linux users.

1.1RPM overview

■The RPM package management mechanism was first proposed by Red Hat. You can learn more about the RPM package management mechanism at its official website http://www.rpm.org.
■Detailed record of software package installation, uninstallation, upgrade and other change information
■Automatic analysis of software package dependencies

—General naming format: bash-4.2.46-28.el7.x86_64.rpm
(where bash is the software name , 4.2.46 is Version number, 28 represents the number of releases , el7 represents the supported system , x86 _64 represents the supported hardware platform , rpm represents the extension )

1.2 Use RPM package management command --rpm

1.2.1 Format of rpm command

■The rpm command can realize almost all the management functions of the RPM software package.
■Execute the "man rpm" command to get detailed help information about the rpm command

Insert picture description here

Insert picture description here

■ rpm command function
Query and verify the relevant information of the RPM software package
Install, upgrade, uninstall the RPM software package,
maintain and rebuild the RPM database information and other comprehensive management operations

1.2.2 Query RPM Software Package Information

Query installed RPM software information
Use the query function of the rpm command to check whether a software package has been installed, understand the purpose of the software package, the files copied to the system, and other related information, so as to better manage the Linux system In the application.

rpm -q 软件名  ——查询指定软件是否已安装

rpm -qi 软件名  ——显示已安装的指定软件的详细信息

rpm -ql 软件名  ——显示已安装的指定软件的文件列表

rpm -qc 软件名  ——列出已安装的指定软件的配置文件

rpm -qd 软件名  ——列出已安装的指定软件的依赖的软件包及文件

rpm -qf 文件或目录  ——查询已安装的指定软件属于哪个安装包

rpm -qa  ——显示当前系统中以 rpm方式安装的所有软件列表

rpm -qa | grep -i postfix  ——查询软件postfix是否已安装

Combined with the pipeline operation, you can count the number of rpm software installed in the system and
Insert picture description here
query the information of the uninstalled RPM software.
When using the "-qp" option, you must use the path of the RPM package file as a parameter (there can be more than one), not the package name . The related sub-options are similar to when using "-q" query, the commonly used options are as follows:

rpm -qpi RPM包文件名  ——查询指定软件包的详细信息

rpm -qpl RPM包文件名  ——查询指定软件包的文件列表

rpm -qpc RPM包文件名  ——查询指定软件包的配置文件

rpm -qpd RPM包文件名  ——查询指定软件包的软件包文档的位置

eg.

2. Install, upgrade, and uninstall RPM packages

rpm [选项] RPM包文件
例如:rpm -ivh RPM软件包
常用选项:
-i       #安装一个新的 RPM 软件包。
-U       #升级某个软件包,若未安装过,则进行安装。
-F       #升级某个软件包,若未安装过,则放弃安装。
-h       #在安装或升级软件包的过程中,以“#”号显示安装进度。
-v       #显示软件安装过程中的详细信息。
--force  #强制安装某个软件包,比如要安装版本更旧的软件包
-e       #卸载指定名称的软件包。
--nodeps #在安装或升级、卸载一个软件包时,不检查与其他软件包的依赖关系。

Before installation, you need to see if the system has this installation package. If there is no installation package, you need to mount the CD and add the installation package.

mount  /dev/cdrom /mnt       #挂载光盘;/dev/cdrom是设备文件名,是/dev/sr0目录的软链接;/mnt是挂载位置
mount  /dev/sr0 /mnt         #挂载光盘,因为/dev/cdrom是 /dev/sr0的软链接,所以命令也可以这样写

2.1 Install and upgrade software packages

When using the rpm command to install a software package, you need to specify the complete package file name as a parameter (there can be more than one)
. When uninstalling the software package, you only need to specify the software name. If you want to install multiple RPM packages at once, you can use the wildcard "*". This method is particularly useful when installing multiple packages that have interdependencies. The system will automatically check the dependencies and determine the installation order without management. To determine which package should be installed first.
When installing a new software package, the "-ivh" combination option is usually used, which facilitates understanding of the software installation process information and timely tracking of the installation progress. If you are using a new version of the software package to replace the old version, you only need to replace "-i" with "-U".

2.2 Uninstall the software package

When uninstalling a software package, the "-e" option is mainly used. For example, execute the "rpm-e elinks" operation to uninstall the installed elinks software, and when you execute the query, you will find that the elinks software is not installed.

[root@kgc~]# rpm -e elinks
[root@kgc~]# rpm -q elinks
[root@kgc~]  paclage elinks is not installed

2.3 Maintain RPM database

When the RPM database is damaged and the Linux system cannot automatically complete the repair, it will cause the normal installation, uninstallation and query of software packages using the rpm command. At this time, you can use the "–rebuilddb" or "–initdb" function of the rpm command to rebuild the RPM database.

Rebuild the RPM database

[root@kgc~]# rpm  --rebuilddb

or

[root@kgc~]# rpm --initdb

Import verification public key

Before importing the public key file for digital signature verification, an error will be reported when installing some of the RPM software packages in the CD. Need to import the public key file located in the root directory of the CD into the RPM database

mount /dev/sr0 /mnt/
rpm --import /mnt/RPM-GPG-KEY-CentOS-7

3. Linux application basics

The relationship between applications and system commands

Character System command application
File location Generally in the /bin and /sbin directories, or shell internal commands Usually in /usr/bin, /usr/sbin and /usr/local/bin, /usr/local/sbin
The main purpose Complete the basic management of the system, such as IP configuration tools Complete other relatively independent auxiliary tasks, such as a web browser
Applicable environment Generally only run in the character operation interface According to actual needs, some programs can be run in the graphical interface
Run format Generally include command words, command options and command parameters Usually there is no fixed execution format, which is defined by the program developer

Directory structure of a typical application

file type Save directory Description
Ordinary executable program file /usr/bin Executable by all users
Server program, management program file /usr/sbin Only the administrator can execute
Application configuration file /etc Applications installed via rpm or yum
Log file / var / log System log
Application Reference Document File /usr/share/doc Reference documents and other data about the application
Application man page file /usr/share/man Man pages for executable files and configuration files

The following takes the postfix software package (a mail server program) installed by default in the CentOS system as an example to show the file composition of the server application. Execute the "rpm -ql postfix" command, you can view the directory and file list of the postfix package installed in the system
Insert picture description here

Common package types

file type Save directory
RPM package The extension is ".rpm", suitable for RHEL, CentOS and other systems
DEB software package The extension is ".deb", suitable for Ubuntu, Debian and other systems
Source code package Generally, the compressed package in the format of ".tar.gz". ".Tar.bz2" contains the original code of the program and needs to be compiled and installed
Package with installer The extensions of the software packages vary. Most of them in TarBall format will provide executable programs or script files for installation, such as install.sh, setup, etc. During installation, you can simply run the installation file according to the wizard. Prompt to complete the installation operation

4. Source code compilation and installation

4.1 Advantages of using source code to install software

Obtain the latest software version, fix bugs in time
, and flexibly customize software functions according to user needs

4.2 Examples of applications

When installing a newer version of the application, when the
currently installed application cannot meet your needs, and when you
need to add new features to the application

4.3 Tarball packet

.tar.gz and .tar.bz2 formats are mostly
Software material reference: http://sourceforge.net

4.4 integrity check

omd5sum verification tool

[root@localhost ~]# md5sum httpd-2.4.25.tar.gz
24fb8b9e36cf131d78caae864fea0f6a httpd-2.4.25.tar.gz
注:httpd-2.4.25.tar.gz前面的就是MD5校验和

4.5 Confirm the source code compilation environment

Need to install a compiler that supports C/C++ programming language such as: gcc, gcc-c++, make,...

4.6 One-click installation of software with multiple dependent packages using yum

If you use the rpm method to install, you need to install multiple dependent packages first, which will be very cumbersome. So use the yum method for one-click installation, you don't need to find and install them one by one.
1) Configure the local yum source warehouse first

mount /dev/cdrom /mnt/       #把光盘挂载到/mnt目录下
cd /etc/yum.repos.d/         #切换到yum.repos.d目录下 
mkdir repos.bak              #新建一个目录,用于备份里面原有的文件或目录
mv * repos.bak               #将所有的里面所有的文件移动到刚创建的目录中,这里最好使用mv *.repo repos.bak

Insert picture description here
Now we will start to build a yum warehouse

vim local.repo
[local]							#仓库类别
name=local						#仓库名称
baseurl=file:///mnt				#指定URL 访问路径为光盘挂载目录
enabled=1						#开启此yum源,此为默认项,可省略
gpgcheck=0						#不验证软件包的签名

yum clean all            		#删除yum缓存
yum makecache               	#更新yum缓存
注:yum clean all && yum makecache可以一步到位,要练习最好分开

Commonly used operating commands in yum

Common commands Description
yum -y install software name Install and upgrade packages, "-y" option means automatic confirmation
yum -y remove software name Uninstall the software package to automatically resolve its dependencies
yum -y update software name Upgrade package
yum list Query the package list
yum list installed Query the installed software packages in the system
yum list available Query packages that have not been installed in the warehouse
yum list updates Query the software packages that can be upgraded
yum info software name example: yum info httpd Query the description information of the software package
yum search [all] Keyword example: yum search all httpd Find related software packages based on a certain keyword
yum whatprovides command example: yum whatprovides netstat Query which package the command belongs to

5. The basic process of compiling and installing

1) tar unpack

  tar zxvf(或jxvf) xxx.tar.gz(或xxx.tar.bz2) -C 目标路径
  格式要对应选项

1
2
2) Configure software modules (installation path, turn on or turn off module functions, user settings for management service processes)

 ./configure --prefix=目标路径(此软件安装到哪里去)

1
3) Compile (convert the source code into an executable program)
make

4) Install
make install

Guess you like

Origin blog.csdn.net/zhangyuebk/article/details/113574277