Skills of using RPM package manager in CentOS system

Time:2020-11-20

rpm: redhat package manager, RPM is Package Manager
Rpm is a software package management method developed by red hat company. With RPM, we can easily install, query, uninstall and upgrade the software. However, the dependency between RPM packages is often cumbersome, especially when the software is composed of multiple RPM packages.
Naming of RPM packages
20151130103130924.jpg (886×362)

For example, bash-4.3.2-1.centos6.x86_ 64.rpm

Application of RPM
install

Copy code

The code is as follows:

rpm {-i|–install} [install-options] PACKAGE_FILE …

-I) installation
-V – display details, which can be superimposed to view more detailed information, such as – VV, – VVV
-H. display the progress and use 50 ා as the progress bar
 
We usually use – IVH in combination to install the RPM package
 
–Nodeps de dependency
–Replace kgs re install
–Test tests the installation, not the actual installation
give an example:

Copy code

The code is as follows:

[[email protected] ~]# rpm -ivh package.rpm

upgrade
rpm {-U|–upgrade} [install-options] PACKAGE_FILE …
If there is an older version of the package, upgrade the installation; if not, install it directly
rpm {-F|–freshen} [install-options] PACKAGE_FILE …
If there is an older version of the package, upgrade the installation; if not, terminate
 
We usually use – uvh, – FVH in combination to install the RPM package
 
[install-options]
— oldpack
— force ignore conflict, enforce
 
be careful:
Linux supports the coexistence of multiple versions of the kernel, so the new version of the kernel can be installed directly;
If the configuration file of the original package has been changed after installation, the file of the new version will not directly cover the file of the old version. Instead, the file of the new version will be renamed (with the suffix. Rpmnew) and preserved;
give an example:

Copy code

The code is as follows:

[[email protected] ~]# rpm -Uvh package.rpm

uninstall

Copy code

The code is as follows:

rpm {-e|–erase} [–allmatches] [–nodeps] [–noscripts] [–notriggers] [–test] PACKAGE_NAME …

–Nodeps ignore dependencies
–Test
give an example:

Copy code

The code is as follows:

[[email protected] ~]# rpm -ev package

query

Copy code

The code is as follows:

rpm {-q|–query} [select-options] [query-options]

[select-options]
1. Query whether the package is installed
     rpm -q PACKAGE_NAME…
2. Query all installed packages
     rpm -qa
3. Query which package installation generated a file
     rpm -qf /path/to/somefile
4. Query information about packages that have not been installed
     rpm -qp PACKAGE_FILE
 
[query-options]
1. Query the brief description of a package
     rpm -qi PACKAGE_NAME
2. Query the list of all files generated after a package is installed
     rpm -ql PACKAGE_NAME
3. Query the list of all configuration files generated after a package is installed
     rpm -qc PACKAGE_NAME
4. Query the list of all help files generated after a package is installed
     rpm -qd PACKAGE_NAME
5. Query the changelog list information that changes with the version of an RPM package
     rpm -q –changelog PACKAGE_NAME
6. Query the capabilities provided by a package
     rpm -q –provides PACKAGE_NAME
7. Query the capabilities that a package depends on
     rpm -q –requires PACKAGE_NAME
8. Query the script when a package is installed and unloaded
     rpm -q –scripts
    
There are four scripts to install and uninstall:
Preinstall: script executed before installation
Postinstall: script executed after installation
Preinstall: script executed before uninstall
Postinstall: script executed after uninstall
give an example:
Query all installed RPM packages in the system
 

Copy code

The code is as follows:

[[email protected] ~]# rpm -qa

Query the list of files contained in the RPM package
 

Copy code

The code is as follows:

[[email protected] ~]# rpm -qlp package

Query the list of help files contained in the RPM package
 

Copy code

The code is as follows:

[[email protected] ~]# rpm -qdp package

check
 

Copy code

The code is as follows:

rpm {-V|–verify} [select-options] [verify-options]

Common usage: RPM – V package_ NAME
 
After the file is changed, the verification will be prompted with the following information:
 
5: MD5 check value of file
S: File size
50: Link file
T: When the file was created
D: Equipment documentation
U: Users of files
G: User groups for files
M: File permissions
give an example:
Use VIM first yum.conf The file is modified and then checked
 

Copy code

The code is as follows:

[[email protected] ~]# rpm -V yum.conf
S.5….T. c /etc/yum.conf

Verification of the validity and integrity of packet source
rpm –import PUBKEY …
Import key
rpm {-K|–checksig} [–nosignature] [–nodigest] PACKAGE_FILE …
Verify key
— nosignature: do not check source legitimacy
— nodigest: do not check integrity
give an example:
 

Copy code

The code is as follows:

[[email protected] ~]# rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-*
[[email protected] ~]# rpm -k /var/ftp/pub/Server/kernel-PAE-2.6.18-194.el5.i686.rpm
/var/ftp/pub/Server/kernel-PAE-2.6.18-194.el5.i686.rpm: (sha1) dsa sha1 md5 gpg OK

Public database / var / lib / rpm

Rebuild database
 

Copy code

The code is as follows:

rpm {–initdb|–rebuilddb}

 
Initialization: – – initdb
If the data does not exist in advance, it is new; otherwise, no operation is performed
 
Rebuild: – – rebuildb
Whether or not a database already exists, the existing database will be directly rebuilt and overwritten
give an example:
 

Copy code

The code is as follows:

[[email protected] ~]# rpm –initdb
[[email protected] ~]# rpm –rebuilddb
yum: Yellow dog Updater,Modified

The main function is to add / delete / update RPM packages more conveniently, which can automatically solve the dependency problem of packages and facilitate the management of a large number of system updates
 
Using rpm2cpio, CPIO extracts specific files in the RPM package
Sometimes, we need to extract some files in the RPM package, which can be quickly extracted through the following methods
First query the files in the RPM package
 

Copy code

The code is as follows:

[[email protected] ~]# rpm -qpl anaconda-11.4.1.62-1.src.rpm
anaconda-11.4.1.62.tar.bz2
anaconda.spec

We need to extract anaconda-11.4.1.62 tar.bz2 This file, execute the following command, extract to the current directory
 

Copy code

The code is as follows:

rpm2cpio anaconda-11.4.1.62-1.src.rpm | cpio -idv anaconda-11.4.1.62.tar.bz2

Note: the file path after CPIO parameter “anaconda-11.4.1.62 tar.bz2 “It must be the same as the relative path of the previous query, otherwise the extraction will not succeed.
Related knowledge description
CPIO Parameter Description:
-The meaning of “t” is the same as “- List”. Note that “relative path” is listed here
-The meaning of “I extract” is the same as “- extract”
-D creates a directory, which is equivalent to “- make directories”
-V redundant information output, equivalent to “- verb”
RPM Parameter Description:
-Q — Query
-L — List
-F — file specifies the file
-P — package specifies the RPM package

Methods of repairing RPM database
The first method:
The RPM DB may be damaged during package installation, upgrade, and uninstall operations. It is necessary to repair the RPM DB through the — rebuild parameter. However, such problems may occur sometimes
 

Copy code

The code is as follows:

[[email protected] lib]# rpm -v –rebuilddb
rpmdb: fatal region error detected; run recovery
error: db4 error(-30982) from dbenv->open: DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index

In this case, you need to manually delete the similar files in the / var / lib / RPM directory__ DB *
 

Copy code

The code is as follows:

rm -fr /var/lib/rpm/__db*

Then run it again

Copy code

The code is as follows:

rpm -v –rebuilddb

That’s OK
The second method:
 

Copy code

The code is as follows:

# cd /var/lib
# mv rpm rpm.old
# mkdir rpm
# rpmdb –initdb
# cp rpm.old/Packages rpm
# rpmdb –rebuilddb

The above two methods can repair RPM dB, please refer to use!

Recommended Today

Stack chain storage

Linked list implementation stack Create three files: stacklinked. H, stacklinked. C, stacklinkedtest. C stackLinked.h #ifndef STACK_LINKED_H_ #define STACK_LINKED_H_ #ifdef __GNUC__ #define DEPRECATED __attribute__( (deprecated) ) #elif defined(_MSC_VER) #define DEPRECATED __declspec( deprecated ) #else #define DEPRECATED #endif #ifndef PTOI #define PTOI( p ) ((int32_t)(int64_t)(p)) #endif #ifndef ITOP #define ITOP( i ) ((void *)(int64_t)(i)) #endif #define ADT […]