Common Linux commands that developers need to be familiar with: rpm

Source: Internet
Author: User

Rpm has five basic operations (excluding creating software packages): installation, uninstallation, upgrade, query, and verification. Let's explain them one by one.

1. Install the RPM package

Rpm packages typically have file names similar to foo-1.0-1.i386.rpm.
This includes the software package name (FOO), version number (1.0), Release number (1), and hardware platform (i386 ).
To install a software package, simply type the following command:
$ Rpm-IVH foo-1.0-1.i386.rpm
Foo ####################################
After rpm is installed, the package name (not necessarily the same as the file name) is printed, and a series of # numbers are printed to indicate the installation progress.
Although the installation of the software package is designed as easy as possible, the following errors may still occur:

  1. The software package has been installed. If your software package has been installed, the following information appears:
    $ Rpm-IVH foo-1.0-1.i386.rpm
    Foo package foo-1.0-1 is already installed error: foo-1.0-1.i386.rpm cannot beinstalled
    If you still want to install the software package, you can use the -- replacepkgs option on the command line. RPM will ignore this error message and forcibly install it.
  2. File conflict if one of the software packages you want to install has been installed when other software packages are installed, the following error message is displayed:
    $ Rpm-IVH foo-1.0-1.i386.rpm
    Foo/usr/bin/Foo conflicts with file from Bar-1.0-1 error: foo-1.0-1.i386.rpm cannot be installed
    To make RPM ignore this error message, use the -- replacefiles command line option.
  3. The unresolved dependency RPM package may depend on other software packages, that is, the software package must be installed after a specific software package is installed. If this unresolved dependency exists when you install a software package. The following information is generated:
    $ Rpm-IVH bar-1.0-1.i386.rpm failed dependencies: foo is needed by bar-1.0-1
    You must install the dependent software package to solve this problem. If you want to force the installation (this is a bad idea, because the installed software package may not run normally), use the -- nodeps command line option.
Ii. Uninstall the RPM package

Uninstalling a software package is as simple as installing a software package:
$ Rpm-e foo
Note that the package name foo is used here, instead of the package file name foo-1.0-1.i386.rpm.
If other software packages depend on the software packages you want to uninstall, an error message is generated when you detach them. For example:
$ Rpm-e foo
Removing these packages wowould break dependencies: foo is needed by bar-1.0-1
If you want RPM to ignore this error and continue uninstallation (this is not a good idea, because the program dependent on this software package may not run), use the -- nodeps command line option.

3. Upgrade the RPM package

The upgrade package is similar to the installation package:
$ Rpm-uvh foo-2.0-1.i386.rpm
Foo ####################################
Rpm will automatically uninstall the installed boss's foo package, and you will not see the relevant information. In fact, you may always use-u to install the software package, because it can run normally even if it has not been installed before.
Because RPM performs Intelligent Software Package upgrade and automatically processes the configuration file, you will see the following information:
Saving/etc/Foo. conf as/etc/Foo. conf. RPM save
This indicates that your modifications to the configuration file may not be compatible with the configuration file.
Therefore, the RPM will first back up the old file and then install the new file. You should resolve the differences between the two configuration files as soon as possible so that the system can continue to run normally.
Because the upgrade actually involves the process of uninstalling and installing the software package, you may encounter errors caused by these two operations.
Another problem you may encounter is: When you use an earlier version of the software package to upgrade the new version of the software, RPM will produce the following error message:
$ Rpm-uvh foo-1.0-1.i386.rpm
Foo package foo-2.0-1 (whichisnewer) is already installed error: foo-1.0-1.i386.rpm cannot be installed
If you do need to downgrade the software package, add the -- oldpackage Command Option.

4. query installed software packages

Run the command rpm-Q to query the database of the installed software package.
Simply run the command rpm-Q Foo to print out the package name, version number, and line number of the foo package:
$ Rpm-Q foo
Foo-2.0-1
In addition to specifying the software package name, you can use the following options to specify which software packages you want to query.
These options are called "Software Package-specific options".
-A: Query all installed software packages.
-F: queries software packages that contain files.
-P: You can specify the information displayed when querying the software package file name. They are called information selection options:
-I: displays software package information, such as description, Release number, size, build date, installation date, platform, and other information.
-L: displays the file list in the software package.
-S: displays the status of all files in the software package.
-D: displays the list of files marked as documents (man manual, info manual, readmes, etc ).
-C: displays the list of files marked as configuration files. These are the files (sendmail. cf, passwd, inittab, etc) to be customized after installation ).
For the files to display the file list, you can add the-V command line option to get the output in the format of LS-L.

5. Verify the Software Package

The verification package is performed by comparing the installed files and the original file information in the package. Verification mainly compares the file size, MD5 verification code, File Permission, type, owner and user group.
The rpm-V command is used to verify a software package. You can use any package selection option to query the packages you want to verify.
The command rpm-V Foo will be used to verify the foo software package.
Another example is to verify the software package containing a specific file: rpm-VF/bin/VI.
Verify all installed software packages: rpm-va
Verify with one RPM package: rpm-VP foo-1.0-1.i386.rpm
If you are worried that your RPM database has been damaged, you can use this method. If everything is verified normally, no output will be generated. If there is any inconsistency, it will be displayed. The output format is an 8-bit long string. Each of the 8-bit characters is used to compare a file with an attribute in the RPM database .. (Point) indicates that the test is successful.
The following characters indicate a test failure on the RPM software package: Show characters-> error source, the comparison relationship is as follows:
5: MD5 Verification Code
S: File Size
L: symbolic connection
T: file modification date
D: Device
U: User
G: User Group
M: mode e (including permissions and file types) If error messages are output, you should carefully consider whether to delete or reinstall the file to solve the problem.

6. Tips

Rpm is not only a tool for installing/uninstalling programs, but also a good tool for system maintenance and diagnosis. You can see the following examples to learn how powerful it is.

  1. If you accidentally delete some files, but you cannot delete them all, what should you do?
    You can enter "rpm-va RPM" to display the File Deletion information on the screen. If you find that some files are lost or damaged, you can reinstall or uninstall the software package before installing it.
  2. If you encounter a file you do not know, you can enter the following command to find out which software package it belongs:
    Rpm-qf/usr/x11r6/bin/xjewel
    The output will be: xjewel-1.6-1
  3. If the above two examples are combined, for example, the file/usr/bin/paste has a problem. If you want to know which software package contains the file, you can simply enter:
    Rpm-VF/usr/bin/paste
  4. To learn more about the program in use, enter the following command to obtain the documentation about the program in the software package:
    $ Rpm-qdf/usr/bin/ispell
    Output result:
    /Usr/man/man4/ispell.4
    /Usr/man/man4/english.4
    /Usr/man/Man1/unsq.1
    /Usr/man/Man1/tryaffix.1
    /Usr/man/Man1/sq.1
    /Usr/man/Man1/munchlist.1
    /Usr/man/Man1/ispell.1
    /Usr/man/Man1/findaffix.1
    /Usr/man/Man1/buildhash.1
    /Usr/INFO/ispell.info.gz
    /Usr/doc/ispell-3.1.18-1/readme
  5. You have found a new koulesrpm, but you do not know what it is. You can enter the following command:
    $ Rpm-QIP koules-1.2-2.i386.rpm
  6. To learn which files are installed in the RPM package of koules, enter:
    $ Rpm-qlp koules-1.2-2.i386.rpm
    Output result:
    /Usr/man/man6/koules.6
    /Usr/lib/games/kouleslib/start. Raw
    /Usr/lib/games/kouleslib/end. Raw
    /Usr/lib/games/kouleslib/destroy2.raw
    /Usr/lib/games/kouleslib/destroy1.raw
    /Usr/lib/games/kouleslib/creator2.raw
    /Usr/lib/games/kouleslib/creator1.raw
    /Usr/lib/games/kouleslib/colize. Raw
    /Usr/lib/games/kouleslib
    /Usr/games/koules

The above are just a few common examples. With the further use of rpm, you will find that its combinations of various function options can achieve more powerful RPM package management functions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.