RPM package management tool
rpm command is a management tool for RPM software packages. Rpm was originally a program used by the Red Hat Linux distribution to manage various Linux packages. It is very popular because it follows GPL rules and is powerful and convenient. Gradually adopted by other distributions. The emergence of RPM package management method makes Linux easy to install and upgrade, which indirectly improves the applicability of Linux.
rpm(option)(parameter)
-a: Query all packages;
-b<Completion stage><Package file>+ or -t <Completion stage><Package file>+: Set the completion stage of the packaging package and specify the file name of the package file;
-c: Only the configuration configuration files are listed, this parameter needs to be used with the "-l" parameter;
-d: Only text files are listed, this parameter needs to be used with the "-l" parameter;
-e <package file> or --erase <package file>: delete the specified package;
-f<file>+: Query the package with the specified file;
-h or --hash: List tags when the package is installed;
-i: Display package related information;
-i<package file> or --install<package file>: install the specified package file;
-l: Display the file list of the package;
-p<package file>+: Query the specified RPM package file;
-q: Use query mode. When encountering any problems, the rpm command will first ask the user;
-R: Display package dependency information;
-s: Display file status, this parameter needs to be used with the "-l" parameter;
-U<package file> or --upgrade<package file>: upgrade the specified package file;
-v: Display the instruction execution process;
-vv: Display the instruction execution process in detail to facilitate troubleshooting.
Package: Specify the rpm package to be manipulated.
How to install rpm packages
Installation of rpm packages can be done using the program rpm. Execute the following command:
rpm -ivh your-package.rpm
Among them, your-package.rpm is the file name of the rpm package you want to install, which is usually placed in the current directory.
The following warnings or prompts may appear during the installation process:
... conflict with ...
It may be that there are some files in the package to be installed that may overwrite existing files. By default, it cannot be installed correctly in this case. You can use rpm --force -i
to force the installation.
... is needed by ...
... is not installed ...
If you have not installed some software required by this package, you can use rpm --nodeps -i
to ignore this information. In other words, rpm -i --force --nodeps
can ignore all dependencies and file problems, no matter what package it is. It can be installed, but this forced installation of the software package cannot guarantee full functionality.
How to install .src.rpm package
Some software packages end with .src.rpm. This type of software package is an rpm package containing source code and needs to be compiled during installation. There are two ways to install this type of software package:
method one:
rpm -i your-package.src.rpm
cd /usr/src/redhat/SPECS
rpmbuild -bp your-package.specs #A specs file with the same name as your package
cd /usr/src/redhat/BUILD/your-package/ #A directory with the same name as your package
./configure #This step is the same as compiling ordinary source code software, you can add parameters
make
make install
Method Two:
rpm -i you-package.src.rpm
cd /usr/src/redhat/SPECS
The first two steps are the same as method one
rpmbuild -bb your-package.specs #A specs file with the same name as your package
At this time, there is a new rpm package in /usr/src/redhat/RPM/i386/
(depending on the specific package, it may be i686, noarch, etc.). This is the compiled binary. document.
Execute rpm -i new-package.rpm
to complete the installation.
How to uninstall rpm packages
Use the command rpm -e
package name. The package name can contain version number and other information, but it cannot have the suffix .rpm. For example, to uninstall the software package proftpd-1.2.8-1, you can use the following format:
rpm -e proftpd-1.2.8-1
rpm -e proftpd-1.2.8
rpm -e proftpd-
rpm -e proftpd
The following formats are not allowed:
rpm -e proftpd-1.2.8-1.i386.rpm
rpm -e proftpd-1.2.8-1.i386
rpm -e proftpd-1.2
rpm -e proftpd-1
Sometimes some errors or warnings may appear:
... is needed by ...
This shows that this software is needed by other software and cannot be uninstalled casually. You can use rpm -e --nodeps to force uninstall.
How to get the files in the rpm package without installing it
Using the tools rpm2cpio and cpio
rpm2cpio xxx.rpm | cpio -vi
rpm2cpio xxx.rpm | cpio -idmv
rpm2cpio xxx.rpm | cpio --extract --make-directories
The parameter i is the same as extract, which means extracting the file. v means to indicate the execution process, d is the same as make-directory, which means to create a directory based on the original path of the file in the package, and m means to keep the update time of the file.
How to view files and other information related to rpm packages
All examples below assume the use of package mysql-3.23.54a-11
rpm -qa lists all installed packages
If you want to find all installed software packages containing a certain string sql
rpm -qa | grep sql
rpm -q mysql
You can get the full name of the mysql software package installed in the system, from which you can get information such as the version of the current software package. In this example, the information mysql-3.23.54a-11 can be obtained
rpm -ql package name
Note that this is the name of the software package that does not include the .rpm suffix, which means that you can only use mysql or mysql-3.23.54a-11 instead of mysql-3.23.54a-11.rpm. If you just want to know where the executable program is placed, you can also use which, for example:
which mysql
rpm -qf `which program name` #Return the full name of the software package
rpm -qif `which program name` #Returns information about the software package
rpm -qlf `which program name` #Return the file list of the software package
Note that this is not a quotation mark, but , which is the key in the upper left corner of the keyboard. You can also use
rpm -qilf` to output package information and file list at the same time.
Note that the method in the previous question only applies to executable programs, while the following method can be used not only for executable programs, but also for any ordinary file. The premise is to know the file name. First get the full path of this program, you can use whereis or which, and then use rpm -qf
For example:
whereisftptop
ftptop: /usr/bin/ftptop /usr/share/man/man1/ftptop.1.gz
rpm -qf /usr/bin/ftptop
proftpd-1.2.8-1
rpm -qf /usr/share/doc/proftpd-1.2.8/rfc/rfc0959.txt
proftpd-1.2.8-1
Source package -> Compile -> Binary package (rpm package / system default package)
rpm naming rules: software (software name, software version) + system (os version, os number of digits) rpm verification: SM5DLUGT -> size modified (type/permission) md5 device L (file path) user group time (modified time)
yum: solve rpm dependency problem
#rpm
mysql57-community-release-el6-8.noarch.rpm # An example of an rpm package
/var/lib/rpm/ # Package full name -> package name database
rpm -Uivh --dodeps xxx # upgrade install verbose hash
rpm -qilpfa|grep xxx # query info list (file location after rpm package installation) package (rpm package) file (which rpm file the file belongs to) all
rpm -e #erase
rpm -V # verify
rpm2cpio | cpio -idv
# rpm default installation location
/etc/ configuration file
/usr/bin/ executable file
/urs/lib/ Function library used by the program
/usr/share/doc/ Manual
/usr/share/man/manual