RPM command examples | Linux
Querying for All Packages
Use the rpm command to list all the packages that are currently installed on your system.
At the shell prompt, type:
[root@fedora-serverA ~]# rpm --query --all
This will give you a long listing of software installed.
Querying Details for a Specific Package
[root@fedora-serverA ~]# rpm --query bash bash-3.2-*
The output should be something similar to the one shown. It shows that you do indeed have the package called bash installed.
[root@fedora-serverA ~]# rpm -qi bash Name : bash Relocations: (not relocatable) Version : 3.2 Vendor: Red Hat, Inc. ....<OUTPUT TRUNCATED>.... URL : http://www.gnu.org/software/bash Summary : The GNU Bourne Again shell (bash) version 3.2 Description : The GNU Bourne Again shell (Bash) is a shell or command language interpreter that is compatible with the Bourne shell (sh). Bash incorporates useful features from the Korn shell (ksh) and the C shell (csh). Most sh scripts can be run by bash without modification. This package (bash) contains bash version 3.2, which improves POSIX compliance over previous versions.
This output gives us a lot of information. It shows the version number, the release, the description, the packager, and more.
[root@fedora-serverA ~]# rpm -ql bash
This lists all the files that come along with the bash package.
To list the configuration files (if any) that come with the bash package, type:
[root@serverA ~]# rpm -qc bash /etc/skel/.bash_logout /etc/skel/.bash_profile /etc/skel/.bashrc
The querying capabilities of rpm are extensive. RPM packages have a lot of information stored in so-called tags. These tags make up the metadata of the package. You can query the RPM database for specific information using these tags. For example, to find out the date that the bash package was installed on your system, you can type
[root@fedora-serverA ~]# rpm -q --qf "[ %{INSTALLTIME:date} \n]" bash Mon 03 Sep 2009 01:35:44 PM PDT
To find out what package group the bash application comes under, type
[root@fedora-serverA ~]# rpm -q --qf "[ %{GROUP} \n]" bash System Environment/Shells
You can always query for more than one package at the same time and also query for multiple tag information. For example, to display the names and package groups for the bash and xterm packages, type
[root@fedora-serverA ~]# rpm -q --qf "[%{NAME} - %{GROUP} - %{SUMMARY} \n]" bash xterm bash - System Environment/Shells - The GNU Bourne Again shell (bash) version 3.2 xterm - User Interface/X - Terminal emulator for the X Window System
To determine what other packages on the system depend on the bash package, type
[root@fedora-serverA ~]# rpm -q --whatrequires bash
Installing with RPM
Process of installing an RPM.
1. Launch a virtual terminal.
2. Assuming your distribution install media disc is mounted at the /media/dvd mount point, change to the directory that usually contains the RPM packages on the DVD. Type
[root@fedora-serverA ~]# cd /media/dvd/Packages/
3. You can first make sure that the file you want is indeed in that directory. Use the ls command to list all the files that start with the letters “lyn” in the directory.
Type
[root@fedora-serverA Packages]# ls lyn* lynx-2.*.rpm
4. Now that you have confirmed that the file is there, perform a test install of the package (this will run through the motion of installing the package without actually installing anything on the system). This is useful in making sure that all the needs (dependencies) of a package are met. Type
[root@fedora-serverA Packages]# rpm --install --verbose --hash --test lynx-* Preparing... ########################################### [100%]
Everything looks okay., If you get a warning message about the signature, you can safely ignore it for now.
5. Now you can perform the actual installation. Type
[root@fedora-serverA Packages]# rpm -ivh lynx-* Preparing.. ########################################### [100%] 1:lynx ########################################### [100%]
6. Run a simple query to confirm that the application is installed on your system.
Type
[root@fedora-serverA Packages]# rpm -q lynx lynx-2.*
The output shows that lynx is now available on the system. Lynx is a text-based web browser. You can launch it by simply typing lynx at the shell prompt. To quit lynx, simply press q. You will get a prompt at the lower-right corner of your terminal to confirm that you want to quit lynx. Press enter to confirm.
As you can see, installing packages via RPM can be easy. But there are times when installing packages is trickier. This is usually due to the issues of failed dependencies.
For example, the lynx package might require the bash package to be already installed on the system before it can be successfully installed.
Let’s step through installing a more complex package to see how dependencies are handled with RPM. Assuming you are still in the Package directory of the DVD media, do the following:
1. Install the package by typing
[root@fedora-serverA Packages]# rpm -ivh gcc-4.* error: Failed dependencies: glibc-devel >= 2.2.90-12 is needed by gcc-4.3.0-8.i386
The preceding output does not look good. The last line tells us that gcc* depends on another package, called glibc-devel*.
2. Fortunately, because we have access to the DVD media that contains most of the packages for this distro in a single directory, we can easily add the additional package to our install list. Type
[root@fedora-serverA Packages]# rpm -ivh gcc-4* glibc-devel-2* error: Failed dependencies: glibc-headers = 2.8-3 is needed by glibc-devel-2.8-3.i386
It looks like this particular partner is not going to be easy to move in. The output again tells us that the glibc-devel* package depends on another package, called glibc-headers*.
3. Add the newest dependency to the install list. Type
[root@fedora-serverA Packages]# rpm -ivh gcc-4* glibc-devel-2* \ > glibc-headers-2* error: Failed dependencies: kernel-headers is needed by glibc-headers-2.8-3.i386 kernel-headers >= 2.2.1 is needed by glibc-headers-2.8-3.i386
After all we have given to this relationship, all we get is more complaining. The last requirement is the kernel-headers* package. We need to satisfy this requirement, too.
4. Looks like we are getting close to the end. We add the final required package to the list. Type
[root@fedora-serverA Packages]# rpm -ivh gcc-4* glibc-devel-2* | > glibc-headers-2* kernel-headers-* Preparing... ###################################### [100%] 1:kernel-headers ###################################### [ 25%] 2:glibc-headers ###################################### [ 50%] 3:glibc-devel ###################################### [ 75%] 4:gcc ###################################### [100%]
Uninstalling Software with RPM
Removing software with RPM is quite easy and can be done in a single step. For example, to remove the lynx package that we installed earlier, we simply need to use the -e option, like so:
[root@fedora-serverA ~ ]# rpm -e lynx
This command will usually not give you any feedback if everything went well. To get a more verbose output for the uninstallation process, add the -vvv option to the command.
A handy feature of RPM is that it will also protect you from removing packages that are needed by other packages. For example, if we try to remove the kernel-headers package
[root@fedora-serverA ~]# rpm -e kernel-headers error: Failed dependencies: kernel-headers is needed by (installed) glibc-headers-2.8-3.i386 kernel-headers >= 2.2.1 is needed by (installed) glibc-headers-2.8-3.i386
Verifying Packages with RPM
A useful option with the RPM tool is the ability to verify a package. What happens is that RPM looks at the package information in its database, which is assumed to be good. It then compares that information with the binaries and files that are on your system.
[root@fedora-serverA ~]# rpm -V bash
The absence of any output is a good sign. You can also verify specific files on the file system that a particular package installed.
For example, to verify that the /bin/ls command is valid, you would type
[root@fedora-serverA ~ ]# rpm -Vf /bin/ls
Again, the lack of output is a good thing.
If something was amiss—for example, if the /bin/ls command had been replaced by a dud version—the verify output might be similar to the one here:
[root@fedora-serverA Fedora]# rpm -Vf /bin/ls SM5....T /bin/ls
If something is wrong, as in the preceding example, RPM will inform you of what test failed. Some example tests are the MD5 checksum test, file size, and modification times.
Package Validation using RPM
You sometimes need to manually tell your system whose digital signature to trust. This explains the reason why you may see some warnings in the earlier procedures when you were trying to install a package (such as this message: “Warning: lynx-2.*.rpm:Header V3 DSA signature: NOKEY, key ID 4f2a6fd2”). To prevent this warning message, you should import Fedora’s digital key into your system’s key ring. Type
[root@fedora-serverA ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora
You might also have to import other vendors’ keys into the key ring. To be extra certain that even the local key you have is not a dud, you can import the key directly from the vendor’s web site. For instance, to import a key from Fedora’s project site, you would type
[root@fedora-serverA ~]# rpm --import http://download.fedora.redhat.com/pub/fedora/linux/releases/9/Fedora/i386/os/RPM-GPG-KEY-fedora
In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.