Linux application basics, RPM overview, compilation and installation process

One, Linux application basics

1. The difference between Linux commands and applications

  • Command files are generally installed together when installing the operating system to assist the management of the operating system itself.
  • The command line is mostly suitable for the general format of "command word option parameter".
  • The command only runs in the character operation interface.
  • For internal commands, they are often integrated in the Bash program instead of executing files independently.
  • The execution files of application commands are mostly relatively small, usually placed in the /bin and /sbin directories.
  • The executable files of the application are usually placed in directories such as /usr/bin, /usr/sbin, /usr/local/bin, and /usr/local/sbin.
  • Applications generally need to be installed separately from the operating system to provide functions that are relatively independent of the operating system, sometimes equivalent to the concept of "software".
  • Application programs generally do not have a fixed execution format, and the running mode is defined by the program developer.
  • Application programs generally do not have a fixed execution format, and the running mode is defined by the program developer.
  • Applications may use a graphical interface, and various forms of applications may use a graphical interface, in various forms; some executable files provided by applications can use the same operating format as Linux commands, so they are often called program commands.

2. The composition of Linux applications

  • Ordinary executable program files: generally stored in the /usr/bin directory, and can be executed by ordinary users.
  • Server program and management program files: generally stored in the /usr/sbin directory, and only the administrator can execute them.
  • Configuration files: Generally stored in the /etc directory, corresponding subdirectories will be created when there are many configuration files.
  • Log files: generally stored in the /var/log directory.
  • Data such as reference documents about the application: generally stored in the /usr/share/doc/ directory.
  • The man page of the executable file and configuration file: generally stored in the /usr/share/man/ directory.

3. Package type of software package

  • RPM software package: The file extension of this software package is ".rpm".
  • DEB software package: The file extension of this software package is ".deb".
  • Source code software package: This type of software package is the original code developed by programmers, usually made into ".tar.gz" or ".tar.bz2".
  • Package with installer: This type of package has different extensions, but it is mostly in TarBall format.
  • The vast majority of open source free software choose to publish in the form of TarBall, while RPM software packages, DEB software packages, etc. use binary file formats, and the code is relatively closed.

Two, RPM overview

1. RPM overview

  • The RPM package management mechanism was first proposed by Red Hat. Later, with the upgrade of the version, more excellent features were gradually incorporated, and it became the recognized package management standard in many Linux distributions.
  • The RPM package manager records in detail the various .rpm software packages installed, uninstalled, and upgraded in the Linux system by establishing a unified file database, and can automatically analyze the dependencies between the software packages to maintain various applications Operate in a coordinated and virtual environment.
  • The software package file encapsulated by the RPM mechanism has a conventional naming format, generally using the file name format of "software name-software version-number of releases. operating system type. hardware architecture type. rpm".

2. RPM package management command-rpm

1) The format of the rpm command

The rpm command has very powerful functions. Combining different command options and sub-options can mainly achieve the following three types of functions.

  • Query and verify the relevant information of the RPM software package.
  • Install, upgrade, and uninstall RPM software packages.
  • Maintain comprehensive management operations such as RPM database information.
2) Query RPM package information

2.1) Query the installed RPM software package information
Common syntax format:
rpm option [package name]
Common options:

  • -q: When you need to query whether a software package has been installed, you can directly use the package name as the query parameter.
  • -qa: Display a list of all software installed by RPM in the current system.
  • -qi: View detailed information such as the name, version, license agreement, and usage description of the specified software package.
  • -ql: Display a list of all directories and files installed by the specified software package in the current system.
  • -qf: Check which software package installed the specified file or directory.
用法实例
[root@localhost ~]# rpm -q elinks lynx
未安装软件包 elinks
未安装软件包 lynx

[root@localhost ~]# rpm -qa
 geocode-glib-3.14.0-2.el7.x86_64 
 libfontenc-1.1.2-3.el7.x86_64

[root@localhost ~]# rpm -qi samba-client
Name	: samba-client
Epoch	0
Version	: 4.4.4

[root@localhost ~]# rpm -ql wget
/etc/wgetrc
/usr/bin/wget

2.2) Query related information in the RPM software package file
Common syntax format:
rpm option package location
Common options:

  • -qpi: View detailed information such as the name, version, license agreement, and usage description of the specified software package.
  • -qpl: View the list of all target directories and files that the software package is about to install.

3. Install, upgrade, and uninstall RPM software packages

Common syntax format:
rpm option package location
Common options:

  • -i: Install a new RPM package in the current system.
  • -e: Uninstall the software package with the specified name.
  • -U: Check and upgrade a certain software package in the system. If the software package has not been installed, it is equivalent to the "-i" option.
  • -F: Check and update a certain software package in the system. If the software package has not been installed, the installation is abandoned.
  • -h: In the process of installing or upgrading the software package, the installation progress will be displayed with "#".
    -v: Display detailed information during software installation.
  • "- -force": Forcibly install a certain software package. You can use this option when you need to replace the installed software package and files, or install a software older than the currently used software version.
  • "- -nodeps": When installing, upgrading, or uninstalling a software package, the dependencies with other software packages are not checked.

4. Maintain RPM database

1) Rebuild the RPM database
RPM database is used to record information about installing, uninstalling, and upgrading applications in the Linux operating system. The RPM software package management system automatically completes the maintenance, and generally does not require user intervention. When the RPM database is damaged (may be caused by accidental deletion of files, illegal shutdown, virus damage, etc.), and the Linux operating system cannot automatically complete the repair, it will cause the rpm command to be unable to normally install, uninstall and query software packages. At this time, you can use the "–rebuilddb" or "–initdb" function of the rpm command to rebuild the RPM database.

[root@localhost ~]# rpm --rebuilddb
[root@localhost ~]# rpm --initdb
2) Import and verify the public key
In the Linux/UNIX application field, quite a few software vendors will digitally sign the released software packages to Ensure the integrity and legality of the software. For users, the official public key file can be used to automatically verify the downloaded software package. If a verification failure prompt appears when installing the software, it means that the software package may have been illegally tampered with.
By default, the public key file used for digital signature verification is provided on the CentOS DVD disc, that is, the RPM-GPG-KEY-redhat-release file located in the root directory of the disc. Before importing the public key file, when installing part of the RPM software package in the CentOS CD, the warning message “warning: …….x86_64.rpm: Header V3 RSA/SHA256 signature, key ID ……: NOKEY” may appear ( Generally does not affect normal use).
When importing the public key file into the RPM database, you need to use the "-import" option. For example, execute the following operations to import the RPM-GPG-KEY-CentOS-7 public key file in the CD-ROM directory into the RPM database.

[root@localhost ~]# rpm --import /media/cdrom/RPM-GPG-KEY-CentOS-7

Three, compile and install process

1. In which cases do you need to compile and install?

Modern Linux distributions usually use the software package management mechanism to package and install the software, which saves the software compilation and installation process and greatly simplifies the installation and use of the Linux operating system. However, in some cases, it is still necessary to use source code compilation to install new applications for the operating system, such as the following situations.

  • When installing newer versions of applications,
    most Linux distributions provide a wealth of applications, and the versions of these programs often lag behind the latest source code version of the software, because most open source software always uses source code The form of is released first, and then binary packaged versions such as .rpm and .deb will gradually appear. Download the latest source code package of the application, compile and install it, and get timely updates in terms of program functions, security patches, etc.
  • When the currently installed program cannot meet the application requirements:
    For the application packaged in RPM format, generally only contains a small part of the functions that the software can achieve, and it is difficult to modify and customize by the user. After reconfiguring, compiling and installing the source code of the program, more flexible and richer functions can be customized. Many Linux server programs are installed using source code compilation to obtain services that are more suitable for the actual application needs of the enterprise.
  • When the currently installed program cannot meet the application requirements:
    For the application packaged in RPM format, generally only contains a small part of the functions that the software can achieve, and it is difficult to modify and customize by the user. After reconfiguring, compiling and installing the source code of the program, more flexible and richer functions can be customized. Many Linux server programs are installed using source code compilation to obtain services that are more suitable for the actual application needs of the enterprise.

2. Compile and install process

Insert picture description here

1) Install the dependent environment package

The installation and operation of a software or service requires the support of various compiled software or library files. If the related dependent software is not installed, the service will not be installed.

2) Unpack

The source code package of open source software is generally in the form of TarBall, with the extension ".tar.gz" or ".tar.bz2", which can be decompressed and released using the tar command.

3) Configuration
  • Before compiling the application, you need to enter the source code directory, check the installation environment through the script under the directory, and pre-configure the software installation directory, function selection and other parameters.
  • The environment check and configuration work is usually completed by the configure script file in the source code directory, and various configuration parameters available can be viewed by executing the "./configure --help" command in the source code directory.
  • The parameter in the form of "–prefix" is common to most open source software. This configuration parameter is used to specify the destination folder for the software package installation. If no configuration parameters are specified, the "configure" script will use the software default values ​​for configuration.
4) Compile

The compilation process is mainly based on the configuration information in the Makefile file (if the configuration operation in the previous step fails, compilation will not be possible), the source code file is compiled to generate binary program modules, dynamic link libraries, executable files, etc. After the configuration is complete, just execute the "make" command in the source code directory to execute the compilation operation.

5) Installation

After the compilation is complete, you can execute the following "make install" command to copy the software execution program, configuration files, help files and other related files to the Linux operating system, that is, the final "installation" process of the application.

Guess you like

Origin blog.csdn.net/wulimingde/article/details/109294357