Packages downloaded outside of yum repositories can be queried and installed with rpm.
After completing this section, students should be able to examine and install downloaded package files.
The rpm utility is a low-level tool that can get information about the contents of package files and installed packages. It gets its information from a local database or the package files themselves.
The general form of a query is:
rpm -q [select-options] [query-options]
rpm --query [select-options] [query-options]
RPM queries: Select options
-q -a: all installed packages
-q PACKAGENAME:
currently installed PACKAGENAME
[root@serverX ~]#rpm -q yumyum-3.4.3-118.el7.noarch
-q -p PACKAGEFILE.rpm:
package file named PACKAGEFILE.rpm
[root@serverX ~]#rpm -q -p http://content.example.com/rhel7.0/x86_64/dvd/Packages/yum-utils-1.1.31-24.el7.noarch.rpmyum-utils-1.1.31-24.el7.noarch.rpm
-q -f FILENAME:
what package provides FILENAME
[root@serverX ~]#rpm -q -f /etc/yum.repos.dyum-3.4.3-118.el7.noarch
RPM queries: Information about content of packages
-q: lists the package's name and version; compare to yum list
-q -i: package information; compare to yum info
-q -l: list of files installed by the specified package
[root@serverX ~]#rpm -q -l yum-rhn-plugin/etc/yum/pluginconf.d/rhnplugin.conf /usr/share/doc/yum-rhn-plugin-2.0.1 /usr/share/doc/yum-rhn-plugin-2.0.1/LICENSE /usr/share/locale/aln/LC_MESSAGES/yum-rhn-plugin.mo ...
-q -c: list just the configuration files
[root@serverX ~]#rpm -q -c yum-rhn-plugin/etc/yum/pluginconf.d/rhnplugin.conf
-q -d: list just the documentation files
[root@serverX ~]#rpm -q -d yum-rhn-plugin/usr/share/doc/yum-rhn-plugin-2.0.1/LICENSE /usr/share/man/man5/rhnplugin.conf.5.gz /usr/share/man/man8/rhnplugin.8.gz /usr/share/man/man8/yum-rhn-plugin.8.gz
-q --scripts: list shell scripts that may run before or after the package is installed or removed
[root@serverX ~]#rpm -q --scripts openssh-serverpreinstall scriptlet (using /bin/sh): getent group sshd >/dev/null || groupadd -g 74 -r sshd || : getent passwd sshd >/dev/null || \ useradd -c "Privilege-separated SSH" -u 74 -g sshd \ -s /sbin/nologin -r -d /var/empty/sshd sshd 2> /dev/null || : postinstall scriptlet (using /bin/sh): if [ $1 -eq 1 ] ; then # Initial installation /usr/bin/systemctl preset sshd.service sshd.socket >/dev/null 2>&1 || : fi preuninstall scriptlet (using /bin/sh): if [ $1 -eq 0 ] ; then # Package removal, not upgrade /usr/bin/systemctl --no-reload disable sshd.service sshd.socket > /dev/null 2>&1 || : /usr/bin/systemctl stop sshd.service sshd.socket > /dev/null 2>&1 || : fi postuninstall scriptlet (using /bin/sh): /usr/bin/systemctl daemon-reload >/dev/null 2>&1 || : if [ $1 -ge 1 ] ; then # Package upgrade, not uninstall /usr/bin/systemctl try-restart sshd.service >/dev/null 2>&1 || : fi
-q --changelog: list change information for the package
[root@serverX ~]#rpm -q --changelog audit* Thu Oct 03 2013 Steve Grubb <sgrubb@redhat.com> 2.3.2-3 resolves: #828495 - semanage port should generate an audit event * Thu Aug 29 2013 Steve Grubb <sgrubb@redhat.com> 2.3.2-2 resolves: #991056 - ausearch ignores USER events with -ua option ...
Querying package files:
[root@serverX ~]#wget http://classroom/pub/materials/wonderwidgets-1.0-4.x86_64.rpm[root@serverX ~]#rpm -q -l -p wonderwidgets-1.0-4.x86_64.rpm/etc/wonderwidgets.conf /usr/bin/wonderwidgets /usr/share/doc/wonderwidgets-1.0 /usr/share/doc/wonderwidgets-1.0/README.txt
The repoquery command can also be used to get information about packages and their contents. It differs from rpm by looking up that information in yum's repositories instead of the local database of installed packages.
The command yum localinstall PACKAGEFILE.rpm can be used
to install package files directly. It automatically downloads any dependencies the package has from any
configured yum repositories.
[root@serverX ~]#yum localinstall wonderwidgets-1.0-4.x86_64.rpm[root@serverX ~]#rpm -q wonderwidgetswonderwidgets-1.0-4.x86_64
rpm -ivh PACKAGEFILE.rpm
can also be used to install package files. However, using yum
helps maintain a transaction history kept by yum (see yum history).
Be careful when installing packages from third parties, not just
because of the software that they may install, but because the
RPM may run arbitrary scripts as root as part of
the installation process.
Files in the RPM package can be extracted without installing the package using cpio, an archiving tool like zip or tar.
Pipe the output of rpm2cpio PACKAGEFILE.rpm into
cpio -id, and it will extract all the files stored
in the RPM package. Subdirectory trees will be created as needed, relative to the current working directory.
Select files can also be extracted by specifying the path of the file:
[root@serverX ~]#rpm2cpio wonderwidgets-1.0-4.x86_64.rpm | cpio -id "*txt"11 blocks[root@serverX ~]#ls -l usr/share/doc/wonderwidgets-1.0/total 4 -rw-r--r--. 1 root root 76 Feb 13 19:27 README.txt
Installed packages can be queried directly with the rpm command. Add a -p option to query a package file before installation.
| Task: | Command: |
|---|---|
| Display information about a package | rpm -q -i NAME |
| List all files included in a package | rpm -q -l NAME |
| List configuration files included in a package | rpm -q -c NAME |
| List documentation files included in a package | rpm -q -d NAME |
| Show a short summary of the reason for a new package release | rpm -q --changelog NAME |
| Display the shell scripts included in a package | rpm -q --scripts NAME |
yum(8), rpm(8), repoquery(1), rpm2cpio(8), and cpio(1) man pages