2008-10-26, 03:17 PM
(This post was last modified: 2008-11-24, 05:25 PM by Dungeon-Dave.)
(based upon posts originally written by anyweb, kZo, Oroshi, grep420)
1. Overview
RedHat invented the RedHat Package Management system to ease installation and maintanence of software. Although you can still download raw source code and manually compile applications yourself, using a package management system like RPM provides a number of advantage:
- no compiling: someone else has already done all the hard work of compiling, which saves you the hassle of getting a compiler and various libraries (Shared Objects)
- package pre-requisites: the RPM package contains information about dependencies, so won't install if the pre-requisite files are missing or too old
- package configuration: the RPM package usually contains some default/example config files - helps setting up the package from new
- installation locations: paths in the RPM package conform to the standard Linux filesystem hierarchy (/usr/bin for binaries, /etc for config files, /var/log for logfiles, etc)
- the RPM database: details of RPM-installed software are stored in an RPM database that can be interrogated to list all installed software, what files the package contains, etc.
2. Basic Commands
1. Listing installed packages: rpm -qa, for example:
Code:
$ rpm -qa | more
basesystem-8.0-5
ethtool-3-1
mktemp-1.5-23
perl-Filter-1.30-7
tcl-8.4.9-3
ed-0.2-38
MAKEDEV-3.19-1
pyxf86config-0.3.19-4
...
2. Showing information about a package: rpm -qi packagename (note that the package name, and not version needed to be specified), for example:
Code:
$ rpm -qi ethtool
Name : ethtool Relocations: (not relocatable)
Version : 3 Vendor: Red Hat, Inc.
Release : 1 Build Date: Thu 03 Mar 2005 11:08:26 PM GMT
Install Date: Wed 19 May 2004 01:16:31 AM BST Build Host: tweety.build.redhat.com
Group : Applications/System Source RPM: ethtool-3-1.src.rpm
Size : 134623 License: GPL
Signature : DSA/SHA1, Fri 20 May 2005 08:35:08 PM BST, Key ID b44269d04f2a6fd2
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://sourceforge.net/projects/gkernel/
Summary : Ethernet settings tool for PCI ethernet cards
Description :
This utility allows querying and changing of ethernet card settings,
such as speed, port, auto-negotiation, and PCI locations.
3. Listing package contents: rpm -ql packagename (again, only name and not version number needs to be given), for example:
Code:
$ rpm -ql bzip2
/usr/bin/bunzip2
/usr/bin/bzcat
/usr/bin/bzcmp
/usr/bin/bzdiff
/usr/bin/bzgrep
/usr/bin/bzip2
/usr/bin/bzip2recover
/usr/bin/bzless
/usr/bin/bzmore
4. Listing which package a file belongs to: rpm -qf /path/to/file - in this case, the absolute path to a filename must be specified. I have used the which command to determine the path in this case:
Code:
$ which nmap
/usr/bin/nmap
$ rpm -qf /usr/bin/nmap
nmap-4.53-1.0.cf.fc4
5. Listing contents of an uninstalled package: rpm -qlp /path/to/thisPackageHere.rpm - to see the contents of a package not yet installed, use the qlp options on the RPM file itself, eg:
Code:
$ rpm -qlp openssl096b-0.9.6b-6.i386.rpm
/lib/libcrypto.so.0.9.6b
/lib/libssl.so.0.9.6b
/usr/share/doc/openssl096b-0.9.6b
/usr/share/doc/openssl096b-0.9.6b/CHANGES
/usr/share/doc/openssl096b-0.9.6b/FAQ
6. Installing a package: rpm -ivh /path/to/thisPackage.rpm. i=install, v=verbose, h=hash signs to show progress, eg:
Code:
# rpm -ivh Bastille-3.0.9-1.0.noarch.rpm
Preparing... ########################################### [100%]
1:Bastille ########################################### [100%]
#
Note that root privileges or equivilent (such as sudo) are needed to install RPM packages.
7. Upgrading a package: similar to above but uses the -U option rather than -i, i.e.: rpm -Uvh /path/to/thisPackage.rpm.
8. Checking packages: rpm -V packagename. Should be silent if there are no problems.
9. Checking ALL packages: rpm -Va. Make take some time, so run this command at quiet times, but a good command to run on a regular basis for a sanity check.
10. Uninstalling package: rpm -e packagename (erase package). If other (installed) packages are dependent upon this package, RPM will refuse to erase it, citing dependency issues.
For more information, use man rpm.
3. Other Considerations
- Upgrade over install: it is possible to "upgrade" a package that doesn't exist, so many people stick to using the -Uvh rather than -ivh options when installing.
- erasing leaves detritus: uninstalling a package usually leaves behind data files (logs, etc) as well as config files, which may need to be manually cleared out. On the other hand, don't assume that erasing will leave behind modified config files - make a backup first if you wish to preserve them!
- finding RPMs: there are many RPM download sites out there - try www.rpmfind.net for a good start, google for others. Some sites dedicated to the development of specific applications often have pre-build RPMs on their download pages for fast install - search around.
- distro-specific RPMs: Some RPMs are suited to specific distros, for example those that end in .fc7.rpm are for Fedora7, those ending in .mdk.rpm are from Mandrake Cooker (for Mandrake/Mandriva).
- "noarch" RPMs: some RPMs ending in .noarch.rpm are not distro-specific and can be installed on any Linux distro, kernel version permitting. Webmin is a good example.
- SRPMs: some RPMs with src in the filename are the source code, not compiled binaries. Installing these will only extract and copy the source code to development areas, not provide you with the actual binaries or applications - ensure you get the right file!
- dependency hell: occasionally an RPM will require some pre-requisite packages, which themselves require other pre-requisites... you'll need to search around for those, or use something like yum (described elsewhere).
- module/library dependency: occasionally RPM will complain about dependency upon a missing package, but a quick rpm -qa shows it is there. Look at installing packagename-devel, which contains library functions not essential to the normal operation of the package but others that depend upon it. It won't affect your original package, but should satisfy the dependency requirements.
- compiled packages: it is still possible to download and compile packages outside of RPM but since they won't be included in the RPM database, RPM won't know they exist - and may still complain about missing dependencies.