RPM has a local package database that stores information about packages including name, version, release, package maintainer, software license, and where the files will be stored. You can use the RPM command to query this package database. By providing options to the RPM command, you can narrow your search down to any of this metadata.
- [Narrator] RPM is used to install local software packages. Once a package is installed, the RPM package database is updated with the package information. We can query that package database. We can also query a package directly, even if it isn't installed. In addition, we can query a file. In reality it's looking through the package database for a reference to the file. This only works for files that belong to software packages. Let's use the RPM command to query the database. In a terminal, type in rpm space dash qa and hit Enter.
The dash q option tells RPM to query and dash a means all packages. We could specify the two options individually, but we can also place them next to each other as you see here. Because we haven't specified a package or a file to query, RPM will query the database. We can see from this list that there's a lot of packages installed. If you'd like to have a sorted list, just type it into sort. Type in rpm space dash qa space pipe space sort, and hit Enter. And now you have an alphabetical list.
Since we know everyone has Bash installed, let's query that. Type in clear and hit Enter. Now type in rpm space dash qi for query information, space dash and hit Enter. Again, we haven't specified to query a package or a file, so this information is coming from the database. The dash qi will show information about the package. In this information, we see name, version, release, install date, and more. Near the bottom, we see the description. We can also narrow our search based on single attributes.
Let's say we wanted to find all packages in the system environment slash shells group. We can do this, we just need to specify it. Type in clear again, and then type in rpm space dash qa space Group with a capital G equals double quote, System with a capital S space, Environment with a capital E slash, Shells with a capital S, double quote, and hit Enter. This shows the packages that have been tagged with system environment shells.
We can also show when all packages were installed, sorted by date. Type in rpm space dash qa space dash dash last. And hit Enter. If you want to see where all of the files in a package were installed, we use dash ql for query list. Type in clear, and then type in rpm space dash ql space yum, and hit Enter. This whole query for for the list of file pas, The yum command installs 180 different files in the different directories. It's nice to have a database to maintain these files.
If we want to slim this list down to just documentation, we can specify the dash d option. Type in clear, and them type in rpm space dash qd for query documentation, space yum, and hit Enter. Or we could use the dash c option to show only configuration files. Type in rpm space dash qc space yum for query configuration files. If you find a file on disk and want to know what package it came from, we can query the database for this as well.
We'll use the dash qf options. Type in rpm space dash qf for query file, space slash bin slash bash. That would be the path of the file. And hit Enter. This shows up the slash bin slash bash file came from the bash package. Being able to identify where software came from can help a lot learning about our Linux system. What is really handy is combining the dash qd, for query documentation, and qf, for query file options. Type in clear, and then type in rpm space dash qdf space slash bin slash bash.
And this shows all of the documentation for the slash bin slash bash command. Any time you find a file on disk, and want to know where the documentation is, use these options. We can also ask the database what this package provides using dash dash provides. Type in clear, then type in rpm space dash q for query space dash dash provides space bash and hit Enter. These are the features that the bash package provides. If you want to see what it requires, you can type in rpm space dash q space dash dash requires space bash, and hit Enter.
Another interesting query option is dash dash changelog. This lets us check the changes to the package. Type in clear, and then type in rpm space dash q space dash dash changelog space bash. And hit Enter. This will show all of the changes that have happened to this package. So far, we've only been querying the database. If we have an RPM file downloaded, we can query the package directly before it's installed. Let's make a directory to put our RPMs in. Type in mkdir space slash tmp slash packages.
And hit Enter. Make sure that you do not use sudo in this case. Now let's download an RPM. We're going to use the yum to do this to save time. We need to install the yum download only plugin first, and then we'll download the httpd package. Type in sudo space yum space install space dash y space yum hyphen plugin hyphen downloadonly. And hit Enter. And type in your password, then hit Enter again.
As soon as that finishes, type in sudo space yum space install space dash dash downloadonly space dash dash downloaddir equals slash tmp slash packages slash httpd. What this is going to do is download the httpd packages into this slash tmp slash packages directory. Now let's cd and do slash tmp slash packages. And then type in ls. You wouldn't normally install the rpm repository after downloading it, however, since we passed the dash dash download only option, and specified the slash tmp packages directory with the dash dash downloaddir option, it only downloaded the packages.
Now that we typed in ls, we can see that we have an httpd package, httpd dash tools package, and a mailcap package, all of which were downloaded with yum. To query a package that hasn't been installed yet, we'll add the dash p option to RPM. Type in clear, and then type in ls. Type in rpm space dash qip space httpd dash two and then hit your Tab key so it fills out the line. And then hit Enter. When we query the database, we just provided dash qi, to query a package, we provide dash qip.
To get a list of all files inside the package and where they'll be installed, provide dash l. Type in rpm space dash qlp space httpd dash two and then hit your Tab key again to complete the line, and then hit Enter. Many of the previous query options will also work on a package as well. Just make sure that you provide the dash p option so that it queries the package and not the database. For more information, check the man page for RPM by typing in man space rpm. And hit Enter.
- List the factors that must be checked before downloading a Linux software package from the internet.
- Cite what must be done before installing software from source.
- State the key difference between a local package manager and a repository-based manager.
- Write what you would specify on the command line to change the rpm query format.
- Explain how a Yum client knows what software can be installed.
- Identify which directory Yum repository configure files are stored.