Package Management with TAR and RPM files
-----------------------------------------
The two most common forms of packages are TAR and RPM.
Common filename extensions:
.rpm = RPM (Redhat Package Manager)
.tar = TAR (Tape Archiver)
.tgz = Compressed (gzipped) TAR
.tar.gz = Also compressed TAR
TAR - Tape ARchiver
-------------------
Tar files usually contain only program source (but may contain binaries).
You can think of TAR as the unix version of PKZIP. It stores multiple
files and directories into one file (optionally compressed).
Tar was originally, and still commonly is, a backup tool. As well as
writing files to a tape drive, it can also write the output to a file.
Example to backup your entire root directory to tape: "tar cvplf /dev/st0 /"
Tar is unusual because the dash (-) is optional for the first set of options.
Most common main options:
c = create archive
t = display contents of a tar archive.
x = extract contents of a tar archive.
Other main options exist for appending, updating, comparing, ... RTFM.
Options modifiers:
v = list files being written
z = [un]compress archive. (used with "t", "c" or "x")
p = keep permissions
l = do not cross filesystems
f = filename to save archive - in this case, device file of a tape drive
File(s) or directories to backup.
Plus many other option modifiers. Again: RTFM.
Examples:
Display the contents of a tar file:
tar -tvf foo.tar
Display the contents of a compressed tar file:
tar tzvf foo.tgz
Extract a compressed tar file:
cd
tar xvzf foo.tgz
Create your own compressed tar file from a directory.
cd
tar cvzf foo.tgz foo # where "foo" is a directory
Compile and installing a package from source code:
# download package "foo-1.1.tgz"
cd # go to home directory or where you'd like to unpack the source.
mkdir wip # create a directory to hold unpacked tar file directories.
cd wip # go to wip.
tar xvzf /home/fred/foo-1.1.tgz # unpack tar file.
cd foo-1.1 # go to directory holding holding foo package.
ls # list directory looking for instructions in text format.
less README* INSTALL* QUICKSTART* # read instructions for making foo.
./configure # commonly used to create "Makefile" used to compile.
less Makefile # look for destination install directories (and change?).
make # compile foo.
# Before installing, you can sometimes run "foo" (./foo or ./bin/foo)
# to see if it works as advertised and you really want to keep it.
make install # install foo.
RPM - Redhat Package Manager
----------------------------
RPMs come in two different types:
1) Source code. Only needed if you are going to recompile.
2) Binary. Compiled executable and all supporting files.
There may be different binary distributions for different processors.
i.e. Alpha, Sparc, Intel, etc.
Sometimes you even see different binary RPMs for different Intel
processors, i386, i486, i586 (Pentium), i686 (PPro, P-II, P-III).
They are upwards compatible. (an i586 binary will run on a i586
and a i686, but may not run on i386 or i486)
The "rpm" command will install, un-install, update, verify, check sig, query
and even create rpm binary files from TAR source files.
RPM also checks for dependencies to help ensure the package will run correctly.
To install an RPM file:
# download foo-1.1.i386.rpm
rpm -ivh foo-1.1.i386.rpm
# "i" = install
# "vh" = print progress bar.
To remove the package:
rpm -e foo
To list the contents of package foo-1.1.i386.rpm
rpm -qlp foo-1.1.i386.rpm
To get a description of package foo-1.1.i386.rpm
rpm -qip foo-1.1.i386.rpm
For a description and file list of previously install package "foo":
rpm -qil foo
To verify all files in package "foo" are installed correctly:
rpm -V foo
To find what RPM package the file "/usr/bin/foo" is in:
rpm -qf /usr/bin/foo
To list all install RPM packages on your system:
rpm -qa | sort | less
To update to a newer version of foo:
rpm -Uvh foo-2.0.i386.rpm
# Removes old version of foo and installs newer version.
# Will also install package if it's not installed.
To update to newer versions of packages ONLY if they are installed:
cd /mnt/cdrom/RedHat/RPMS
rpm -Fvh *rpm
# the "F" (freshen) option is new with Redhat 6.0.
# Do NOT use the "U" option, it will INSTALL EVERYTHING!
To update to a newer version of glib over the internet via FTP:
rpm -Fvh ftp://updates.redhat.com/6.0/i386/glib-1.2.3-1.i386.rpm
# HTTP URLs are also valid.
# Wildcards (*) do not seem to work, at least on FTP.
Advanced RPM usage: (not typically for beginners)
-------------------
To extract files from a RPM file to a directory without installing it.
"rpm2cpio" archives the files to standard out in CPIO format.
Example:
cd wip/foo
rpm2cpio foo-2.0.i386.rpm | cpio -ivmud
Building your own RPM files from TAR source code archives.
When you install source RPMs (SRPMs), the files install under the
/usr/src/redhat directory in to the following subdirectories:
/usr/src/redhat/BUILD
Used to uncompress and compile the TAR source archive.
/usr/src/redhat/RPMS
Where you'll find the binary RPM file produced.
/usr/src/redhat/SOURCES
For the source TAR files and patch files.
/usr/src/redhat/SPECS
Holds the "spec" file with instructions for building the RPM.
/usr/src/redhat/SRPMS
Where you'll find the resulting Source RPM file.
The "spec" file contains all the information for the RPM.
Name, version, release, copyright, group, URLs, Vendors, packager,
source code, patch files, commands for building and installing,
all filename that will be installed, all doc files that will be
installed, pre/post install scripts, pre/post removal scripts,
extra dependency information (RPM build automatically finds common
library dependencys and includes them), and much more.
Before attempting to build your own RPM, read the "Maximum RPM" book.
The actual book can be purchased from redhat or book retailers.
There is a free version of it available for download on the net,
and there is a postscript version of it on BSware (as an "extra").