6.2. Transactions with the rpm Command
To set up an RPM transaction, you don't have to do much. All you need to do is pass more than one RPM package on the rpm command line. For example, to set up a transaction for installing three packages, use a command like the following:
rpm -ihv package1.rpm package2.rpm package3.rpm
If any of the packages fail to install, the rpm command will not install any packages. All of the packages will be installed, or none.
This way, if you have a number of packages that together perform some function, such as an Integrated Development Environment (IDE), along with program-language compilers and other software-development tools, you can ensure that all get installed.
As an example, say you need to install the gnorpm package, which provides a graphical front end for the rpm command, and the rpmrebuild package, which allows you to create RPMs from already-installed packages.
Cross Reference
You can install these packages with a transaction by using the following command:
# rpm -ihv gnorpm-0.9-1.i386.rpm rpmrebuild-1.0-0.noarch.rpm
Preparing... ########################################### [100%]
package gnorpm-0.9-1 is already installed
The rpmrebuild package can be installed. (We know this since the rpm command did not issue an error about this package.) But because it was on the same command line as the gnorpm package, the transaction failed. No packages were installed.
To check that the rpmrebuild package was not installed (that is, to check that the transaction worked as expected), you can use the rpm –q command to see if the rpmrebuild package was installed or not. To do so, use a command like the following:
# rpm -q rpmrebuild
package rpmrebuild is not installed
This shows that the rpmrebuild package was not installed, even though the package could be installed on its own. To check that the package could be installed, you can use the --test option, as shown following:
# rpm -i --test rpmrebuild-1.0-0.noarch.rpm
#
This command shows that the rpmrebuild package would install successfully on its own. If there were problems, the rpm command would have issued an error message.
This example shows that when you try to install multiple packages with the rpm command, should any fail, the rpm command will not install any.
The rpm command works similarly for removing packages and upgrading packages. When removing packages, you’ll see an error like the following if any of the packages on the command line cannot be removed:
# rpm -e setup jikes-1.17
error: Failed dependencies:
setup is needed by (installed) basesystem-8.0-1
setup >= 2.0.3 is needed by (installed) initscripts-6.95-1
setup >= 2.5.4-1 is needed by (installed) filesystem-2.1.6-5
setup is needed by (installed) xinetd-2.3.7-2
setup is needed by (installed) dump-0.4b28-4
The setup package could not be removed because it had several capabilities needed by other packages. You can check that the jikes package was not removed by using the rpm –q command, even though it had no failed dependencies:
# rpm -q jikes
jikes-1.17-1
This package was not removed because it appeared as part of the same command that failed, so none of the operations were performed.
When upgrading, you will also see an error message if any of the package upgrades fail. For example:
# rpm -Uhv jikes-1.14-1.i386.rpm autoupdate-3.1.5-1.noarch.rpm
error: jikes-1.14-1.i386.rpm cannot be installed
You can then check that the jikes package, in this example, was not downgraded to the earlier version with the rpm –q command:
# rpm -q jikes
jikes-1.17-1
The rpm command gives every package installed a transaction ID. The transaction ID is a Unix time stamp (number of seconds since January 1, 1970). You can then perform some operations on packages based on the transaction ID.
Note
The fact that a transaction ID uses a Unix timestamp may change in the future.
All the packages installed at the same time are given the same transaction ID. This means that you can perform operations on a set of packages, the packages that were installed together.
But there’s also a downside to this. All the packages installed when you first installed or upgraded your Linux system are given the same transaction ID. This means you cannot selectively act on these packages using the transaction ID, because you will likely get far more packages than you want to work on.
6.2.1.1. Viewing RPM Transaction IDs
To view the install transaction ID (a date code) for a given package, you can use a command like the following:
$ rpm -q --qf "%-20{NAME} %-20{INSTALLTID}\n" jikes
jikes 1035589778
This command uses the --qf or --queryformat option to specify the data to return from the RPM query command. In this case, the command requests the name of the package as well as the transaction ID (TID) for installation.
Cross Reference
There is also a transaction ID for removal, the REMOVETID. You can also query for this ID. For example, if a package hasn't been removed, you'll see an entry like the following:
$ rpm -qa --qf "%-20{NAME} %-20{REMOVETID}\n" termcap
termcap (none)
6.2.1.2. Viewing the Packages Associated with a Transaction ID
Once you have a transaction ID, you can use the --tid option, short for transaction ID, to query for the package associated with a given transaction, using a command like the following:
$ rpm -q --tid 1035589778
jikes-1.17-1
This example uses the transaction ID that the earlier query example returned. If you installed more than one package at the same time, you will see a listing of all the packages that share the transaction ID.
For example, to see many packages with one transaction ID, you can query for packages installed when you installed or upgraded your version of Linux. First, query for the transaction ID of a package you know was installed with the Linux distribution, such as setup on a Red Hat system:
$ rpm -q --qf "%-20{NAME} %-20{INSTALLTID}\n" setup
setup 1033838323
Second, use this transaction ID and query for all packages with this ID, using code like the following:
$ rpm -q --tid 1033838323 | more
redhat-menus-0.26-1
glibc-2.2.93-5
cracklib-2.7-18
gdbm-1.8.0-18
gmp-4.1-4
libacl-2.0.11-2
libjpeg-6b-21
linc-0.5.2-2
pcre-3.9-5
shadow-utils-20000902-12
libtermcap-2.0.8-31
freetype-2.1.2-7
info-4.2-5
fileutils-4.1.9-11
psmisc-20.2-6
ntp-4.1.1a-9
mount-2.11r-10
cracklib-dicts-2.7-18
krb5-libs-1.2.5-6
cyrus-sasl-2.1.7-2
usermode-1.63-1
Xft-2.0-1
Note
Be sure to replace the transaction ID shown here with the transaction ID obtained by querying your system.
This example shows just a few of the packages installed when the Red Hat Linux was installed.
With these options, you can find the transaction IDs for given packages and can use the rpm command to install, remove, or otherwise modify the packages that share a transaction ID.