Linux: Installing Packages with RPM
scottalanmiller last edited by scottalanmiller
Of course, what good is a package management system if we cannot install packages using it? Not very useful, that's the answer. Apart from researching packages, installing is the next more common usage of the RPM system and it is very easy to use. Keep in mind that RPM is a "low level" package management system and, for the most part, we only use this in cases where we need to fix things or understand why higher level tools have failed. As an active Linux administrator you should not, under normal circumstances, use RPM directly for installations. So the instructions here should not be taken to reflect how hard it is to work on Linux normally as we are getting our hands dirty under the hood.
Installing RPM packages with the rpm command is very easy. At its simplest, all we need is the "-i" or "install" flag and it takes care of itself. A package can be sitting for us on the local filesystem, on an NFS share, on the web or similar. Assuming we have downloaded an RPM to the /tmp directory, an install might look like this:
# rpm -i /tmp/openfire.rpm
That's it. The package will install from that command alone. In the bulk of cases it is very handy to have some visibility into what is happening so we typically by default add the "-v" or verbose flag and also the "-h" or hashes flag. The latter flag adds hashes to the output so that we can see how the installation process is moving along. Verbose and hashes would not be used in a script, typically, but when installing by hand are good enough to just make part of your standard routine. Eventually you will never consider running rpm without them. The same command would then be:
# rpm -ivh /tmp/openfire.rpm
It is actually uncommon to use the install or "-i" option as this is better covered by the upgrade or "-U" option. How an upgrade works is that if a package does not exist it will be installed. If the package is already installed but is an older version then the package will be updated automatically by the rpm command. Very handy for many reasons. So it is very standard for installs to be done using this option.
# rpm -Uvh /tmp/openfire.rpm
We may also want to update a package, but only if the package is already installed and to do nothing if it is not already installed. This action is called "to Freshen" a package. The freshen or "-F" flag handles this for us. Freshening is extremely common in scripts where we might want to update many packages but not to cause new ones to be installed.
# rpm -Fvh /tmp/openfire_newversion.rpm
We may also want to install a package using the same version that is already installed in case something bad has happened or for testing. By default the rpm protects against this and will block this from happening, so it is safe to try installing the same package twice. You will simply get an error. But we can force the system to run the installation again overwriting all of the files that were already there using "--force". This is very useful should a file become corrupt or damaged in some way.
# rpm -ivh --force /tmp/openfire.rpm
A very important part of the purpose of a package manager like RPM is that it looks for dependencies and makes sure that we have everything that is needed in order to install the package that we want to install. In nearly all cases we would want the system to fail and warn us if this were the case and, by default, rpm does this. But there are times when we do not want this behaviour. Primarily if we are installing a package with extended functionality and we know what will not work and are aware of the limitations of our decision or, as always, for testing. We change the behaviour of rpm with the "--nodeps" flag option, which stands for "check no dependencies".
# rpm -ivh --nodeps /tmp/openfire.rpm
That wraps up the common flags and options that we will use for installing packages with the rpm command. There are, again, many installation options available in the command documentation but any beyond the ones listed here would typically be special case commands and can be looked up in the reference manual when needed.
The three common installation locations for RPMs are from local filesystem (such as when we download a file to /tmp), from a standard shared file location (such as a mounted NFS package repository) or from a web site. No special syntax needed, but for reference:
# rpm -Uvh /tmp/mypackagethatIdownloaded.rpm # rpm -Uvh /net/myrpmfileserver/repo/mypackage.rpm # rpm -Uvh http://www.coolsitewithrpms.com/centos7/amd64/awesomepackage.rpm