HUB
Sign inSign up

marlabsdocker/lesson8

By marlabsdocker

•Updated almost 9 years ago

Introduction to Linux. Lesson 8. Software Management with RPM.

0

0

marlabsdocker/lesson8 repository overview

++++++++++++++++++++++++++++

⁠THE RPM PACKAGE MANAGER.

⁠++++++++++++++++++++++++++++

The Red Hat Package Manager (RPM) allows the easy installation and removal of software packages—typically, precompiled software. A package consists of an archive of files and other metadata. It is wonderfully easy to use, and several graphical interfaces have been built around it to make it even easier. Several Linux distributions (distros) and various third parties use this tool to distribute and package their software. In fact, almost all of the software mentioned in this book is available in RPM form. The reason you’ll go through the process of compiling software yourself in other chapters is so that you can customize the software to your system, as such customizations might not be readily possible in an RPM. An RPM file is a package that contains files needed for the software to function correctly. These files can be configuration files, binaries, and even pre- and postscripts to run while installing the software. NOTE In the present context mentioned, we are assuming that the RPM files contain precompiled binaries. However, adhering to the open source principle, the various commercial and noncommercial Linux distros are obliged to make the source code for most GNU binaries available. (Those who don’t make it available by default are obliged to give it to you if you ask for it.) Some Linux vendors stick to this principle more than others. Several Linux vendors, therefore, make the source code for their binaries available in RPM form. For instance, Fedora and SuSE also make source code available as an RPM, and it is becoming increasingly common to download and compile source code in this fashion. The RPM tool performs the installation and uninstallation of RPMs. The tool also maintains a central database of what RPMs you have installed, where they are installed, when they were installed, and other information about the package. In general, software that comes in the form of an RPM is less work to install and maintain than software that needs to be compiled. The trade-off is that by using an RPM, you accept the default parameters supplied in the RPM. In most cases, these defaults are acceptable. However, if you need to be more intimately aware of what is going on with a piece of software, you may find that by compiling the source yourself, you will learn more about what software components and options exist and how they work together. Assuming that all you want to do is install a simple package, RPM is perfect. There are several great resources for RPM packages, including the following: ▼ http://rpm.pbone.net⁠ ■ http://ftp.redhat.com⁠ ■ http://mirrors.kernel.org⁠ ▲ http://freshrpms.net⁠ Of course, if you are interested in more details about RPM itself, you can visit the RPM web site at www.rpm.org⁠. RPM comes with Fedora, OpenSuSE, Mandrake, and countless other Red Hat derivatives, and, most surprising of all, the Red Hat version of Linux! If you aren’t sure if RPM comes with your distribution, check with your vendor. NOTE Although the name of the package says “Red Hat,” the software can be used with other distributions as well. In fact, RPM has even been ported to other operating systems, such as Solaris, AIX, and IRIX. The source code to RPM is open source software, so anyone can take the initiative to make the system work for them. The primary functions of the RPM are ▼ Querying, installing, and uninstalling software ■ Maintaining a database that stores various items of information about the packages ▲ Packaging other software into an RPM form Command-Line Option Description --install This installs a new package. --upgrade This upgrades or installs the package currently installed to a newer version. --erase Removes or erases an installed package. --query This is the option used for querying. --force This is the sledgehammer of installation. Typically, you use it when you’re knowingly installing an odd or unusual configuration and RPM’s safeguards are trying to keep you from doing so. The --force option tells RPM to forego any sanity checks and just do it, even if it thinks you’re trying to fit a square peg into a round hole. Be careful with this option. -h Prints hash marks to indicate progress during an installation. Use with the -v option for a pretty display. --percent Prints the percentage completed to indicate progress. It is handy if you’re running RPM from another program, such as a Perl script, and you want to know the status of the install. -nodeps If RPM is complaining about missing dependency files, but you want the installation to happen anyway, passing this option at the command line will cause RPM to not perform any dependency checks. -q Queries the RPM system for information. --test This option does not perform a real installation; it just checks to see whether an installation would succeed. If it anticipates problems, it displays what they’ll be. -V Verifies RPMs or files on the system. -v Tells RPM to be verbose about its actions.

⁠+++++++++++++++++++++++++++++++++

⁠MANAGING SOFTWARE USING RPM.

⁠+++++++++++++++++++++++++++++++++

In the following sections, we will cover details of querying, installing, uninstalling, and verifying software on Red Hat–based systems. Actual examples are used to facilitate understanding. Querying for Information the RPM Way (Getting to Know One Another) One of the best ways to begin any relationship is by getting to know the other party. Some of the relevant information might be the person’s name, what they do for a living, date of birth, what they like or dislike, etc. The same rules apply to RPM-type packages or dpkg packages. After you obtain a piece of software (from the Internet, from the distribution’s CD/DVD, from a third party, etc.), you should get to know the software before making it a part of your life . . . sorry—your system. This functionality was built into RPM and dpkg from the beginning, and it is easy to use. When you get used to Linux/UNIX, you may find that software names are somewhat intuitive, and you can usually tell what a package is just by looking at its name. For example, to the uninitiated, it may not be immediately obvious that a file named gcc-4.1.2.rpm is a package for the “GNU Compiler collection.” But once you get used to the system and you know what to look for, it becomes more intuitive. You can also use RPM or dpkg to query for other types of information, such as the package’s build date, its weight ( . . . sorry—its size), its likes and dislikes ( . . . sorry—its dependencies), etc. Let’s start by trying a few things using RPM and dpkg. Begin by logging into the system and start a terminal (as per the previous Tip). Querying for All Packages Use the rpm command to list all the packages that are currently installed on your system. At the shell prompt, type: [root@fedora-serverA ~]# rpm --query --all This will give you a long listing of software installed. NOTE Like most Linux commands, the rpm command also has its own long forms and short (or abbreviated) forms of options or arguments. For example, the short form of the --query option is -q, and the short form for --all is -a. We will mostly use short forms in this book, but we’ll occasionally use the long forms just so you can see their relationship.

⁠+++++++++++++++++++++++++++++++++

⁠Querying Details for a Specific Package.

⁠+++++++++++++++++++++++++++++++++

Let’s zero in on one of the packages listed in the output of the preceding command, the bash application. Use rpm to see if you indeed have the bash application installed on your system. [root@fedora-serverA ~]# rpm --query bash bash-3.2-* The output should be something similar to the one shown. It shows that you do indeed have the package called bash installed. It also shows the version number appended to the package name. Note that the version number of the output on your system might be different; however, the main package name will almost always be the same, i.e., bash is bash is bash is bash in OpenSuSE, Fedora, Mandrake, RHEL, Ubuntu, etc.

There are several ways to type a command at the shell. One way is to use a nice, windowed (GUI) terminal; another is to use the system console. The windowed consoles are known as terminal emulators (or pseudo-terminals), and there are tons of them. After logging into your chosen desktop (GNOME, KDE, Xforms Cool Environment [XFCE], etc.), you can usually launch a pseudoterminal by right-clicking the desktop and selecting Launch Terminal from the context-sensitive menu. If you don’t have that particular option, look for an option in the menu that says Run Command (or press the alt and f2 keys simultaneously to launch the Run Application dialog box). After the Run dialog box appears, you can then type the name of a terminal emulator into the Run text box. Which brings us to the next question. What is bash and what does it do? To find out, type [root@fedora-serverA ~]# rpm -qi bash Name : bash Relocations: (not relocatable) Version : 3.2 Vendor: Red Hat, Inc. ........ URL : http://www.gnu.org/software/bash⁠ Summary : The GNU Bourne Again shell (bash) version 3.2 Description : The GNU Bourne Again shell (Bash) is a shell or command language interpreter that is compatible with the Bourne shell (sh). Bash incorporates useful features from the Korn shell (ksh) and the C shell (csh). Most sh scripts can be run by bash without modification. This package (bash) contains bash version 3.2, which improves POSIX compliance over previous versions. This output gives us a lot of information. It shows the version number, the release, the description, the packager, and more. The bash package looks rather impressive. Let’s see what else comes with it. [root@fedora-serverA ~]# rpm -ql bash This lists all the files that come along with the bash package. To list the configuration files (if any) that come with the bash package, type: [root@serverA ~]# rpm -qc bash /etc/skel/.bash_logout /etc/skel/.bash_profile /etc/skel/.bashrc The querying capabilities of rpm are extensive. RPM packages have a lot of information stored in so-called tags. These tags make up the metadata of the package. You can query the RPM database for specific information using these tags. For example, to find out the date that the bash package was installed on your system, you can type [root@fedora-serverA ~]# rpm -q --qf "[ %{INSTALLTIME:date} \n]" bash Mon 03 Sep 2009 01:35:44 PM PDT NOTE Because bash is a standard part of most Linux distros and would have been installed when you initially installed the operating system (OS), you will find that its install date will be close to the day you installed the OS. To find out what package group the bash application comes under, type [root@fedora-serverA ~]# rpm -q --qf "[ %{GROUP} \n]" bash System Environment/Shells You can, of course, always query for more than one package at the same time and also query for multiple tag information. For example, to display the names and package groups for the bash and xterm packages, type [root@fedora-serverA ~]# rpm -q --qf "[%{NAME} - %{GROUP} - %{SUMMARY} \n]" bash xterm bash - System Environment/Shells - The GNU Bourne Again shell (bash) version 3.2 xterm - User Interface/X - Terminal emulator for the X Window System To determine what other packages on the system depend on the bash package, type [root@fedora-serverA ~]# rpm -q --whatrequires bash TIP The RPM queries noted here were done on software that is currently installed on the system. You can perform similar queries on software that you get from other sources as well—for instance, software that you are planning to install that you have obtained from the Internet or from the distribution CD/DVD. Similar queries can also be performed on packages that have not yet been installed. To do this, you simply add the -p option to the end of the query command. For example, to query an uninstalled package named “joe-3.1.6.i386.rpm,” you would type rpm -qip joe-3.1-6.i386.rpm. Installing with RPM (Moving In Together) OK, you are now both ready to take the relationship to the next stage. You have decided to move in together. This can be a good thing, because it allows both of you to see and test how truly compatible you are. This stage of relationships is akin to installing the software package on your system, i.e., moving the software into your system. In the following procedures, you will install the application called “lynx” onto your system. First, you will need to get a copy of the rpm package for lynx. You can get this program from several places (the install CDs/DVD, the Internet, etc.). The example that follows uses a copy of the program that came with the DVD used during the installation. The CD/DVD needs to be mounted in order to access its content. To mount it, insert the DVD into the drive and launch a console. You should see an icon for the DVD appear on the desktop after a brief delay. The RPM files are stored under the Fedora/RPMS directory under the mount point of your DVD/CD device, e.g., the /media/dvd/Packages/ directory. NOTE If you don’t have a Fedora CD or DVD, you can download the RPM we will be using in the next section from http://download.fedora.redhat.com/pub/fedora/linux/releases/9/Everything/i386/os/⁠ Packages/lynx-2.8.6-13.fc9.i386.rpm. Let’s step through the process of installing an RPM.

  1. Launch a virtual terminal.
  2. Assuming your distribution install media disc is mounted at the /media/dvd mount point, change to the directory that usually contains the RPM packages on the DVD. Type [root@fedora-serverA ~]# cd /media/dvd/Packages/
  3. You can first make sure that the file you want is indeed in that directory. Use the ls command to list all the files that start with the letters “lyn” in the directory. Type [root@fedora-serverA Packages]# ls lyn* lynx-2.*.rpm
  4. Now that you have confirmed that the file is there, perform a test install of the package (this will run through the motion of installing the package without actually installing anything on the system). This is useful in making sure that all the needs (dependencies) of a package are met. Type [root@fedora-serverA Packages]# rpm --install --verbose --hash --test lynx-* Preparing... ########################################### [100%] Everything looks okay., If you get a warning message about the signature, you can safely ignore it for now.
  5. Go ahead and perform the actual installation. Type [root@fedora-serverA Packages]# rpm -ivh lynx-* Preparing.. ########################################### [100%] 1:lynx ########################################### [100%]
  6. Run a simple query to confirm that the application is installed on your system. Type [root@fedora-serverA Packages]# rpm -q lynx lynx-2.* The output shows that lynx is now available on the system. Lynx is a text-based web browser. You can launch it by simply typing lynx at the shell prompt. To quit lynx, simply press q. You will get a prompt at the lower-right corner of your terminal to confirm that you want to quit lynx. Press enter to confirm. As you can see, installing packages via RPM can be easy. But there are times when installing packages is trickier. This is usually due to the issues of failed dependencies. For example, the lynx package might require the bash package to be already installed on the system before it can be successfully installed. Let’s step through installing a more complex package to see how dependencies are handled with RPM. Assuming you are still in the Package directory of the DVD media, do the following:
  7. Install the package by typing [root@fedora-serverA Packages]# rpm -ivh gcc-4.* error: Failed dependencies: glibc-devel >= 2.2.90-12 is needed by gcc-4.3.0-8.i386 The preceding output does not look good. The last line tells us that gcc* depends on another package, called glibc-devel*.
  8. Fortunately, because we have access to the DVD media that contains most of the packages for this distro in a single directory, we can easily add the additional package to our install list. Type [root@fedora-serverA Packages]# rpm -ivh gcc-4* glibc-devel-2* error: Failed dependencies: glibc-headers = 2.8-3 is needed by glibc-devel-2.8-3.i386 Uh oh . . . it looks like this particular partner is not going to be easy to move in. The output again tells us that the glibc-devel* package depends on another package, called glibc-headers*.
  9. Add the newest dependency to the install list. Type [root@fedora-serverA Packages]# rpm -ivh gcc-4* glibc-devel-2* \

glibc-headers-2* error: Failed dependencies: kernel-headers is needed by glibc-headers-2.8-3.i386 kernel-headers >= 2.2.1 is needed by glibc-headers-2.8-3.i386 After all we have given to this relationship, all we get is more complaining. The last requirement is the kernel-headers* package. We need to satisfy this requirement, too.

  1. Looks like we are getting close to the end. We add the final required package to the list. Type [root@fedora-serverA Packages]# rpm -ivh gcc-4* glibc-devel-2* |

glibc-headers-2* kernel-headers-* Preparing... ###################################### [100%] 1:kernel-headers ###################################### [ 25%] 2:glibc-headers ###################################### [ 50%] 3:glibc-devel ###################################### [ 75%] 4:gcc ###################################### [100%]

It was tough, but you managed to get the software installed. TIP When you perform multiple RPM installations in one shot, as you did in the previous step, it is called an RPM transaction. A popular option used in installing packages via RPM is the -U (for Upgrade) option. It is especially useful when you want to install a newer version of a package that already exists. It will simply upgrade the already installed package to the newer version. This option also does a good job of keeping your custom configuration for an application intact. For example, if you had lynx-7-2.rpm installed and you wanted to upgrade to lynx-7-9.rpm, you would type rpm -Uvh lynx-7-9.rpm.

⁠++++++++++++++++++++++++++++++++++++++++

⁠Uninstalling Software with RPM .

⁠+++++++++++++++++++++++++++++++++++

Things didn’t quite work out the way you both had anticipated. Now it is time to end the relationship. The other partner was never any good anyhow, so we’ll simply clean them out of our system. Cleaning up after itself is one of the areas in which RPM truly excels. And this is one of its key selling points as a software manager in Linux systems. Because a database of various pieces of information is stored and maintained along with each installed package, it is easy for RPM to refer back to its database to collect information about what was installed and where.

Removing software with RPM is quite easy and can be done in a single step. For example, to remove the lynx package that we installed earlier, we simply need to use the -e option, like so: [root@fedora-serverA ~ ]# rpm -e lynx This command will usually not give you any feedback if everything went well. To get a more verbose output for the uninstallation process, add the -vvv option to the command. A handy feature of RPM is that it will also protect you from removing packages that are needed by other packages. For example, if we try to remove the kernel-headers package (recall that the gcc package depended on it), we’d see the following: [root@fedora-serverA ~]# rpm -e kernel-headers error: Failed dependencies: kernel-headers is needed by (installed) glibc-headers-2.8-3.i386 kernel-headers >= 2.2.1 is needed by (installed) glibc-headers-2.8-3.i386

⁠+++++++++++++++

⁠Verifying Packages

⁠+++++++++++++++

A useful option with the RPM tool is the ability to verify a package. What happens is that RPM looks at the package information in its database, which is assumed to be good. It then compares that information with the binaries and files that are on your system. In today’s Internet world, where being hacked is a real possibility, this kind of test should tell you instantly if anyone has done something to your system. For example, to verify that the bash package is as it should be, type [root@fedora-serverA ~]# rpm -V bash The absence of any output is a good sign. You can also verify specific files on the file system that a particular package installed. For example, to verify that the /bin/ls command is valid, you would type [root@fedora-serverA ~ ]# rpm -Vf /bin/ls Again, the lack of output is a good thing. If something was amiss—for example, if the /bin/ls command had been replaced by a dud version—the verify output might be similar to the one here: [root@fedora-serverA Fedora]# rpm -Vf /bin/ls SM5....T /bin/ls If something is wrong, as in the preceding example, RPM will inform you of what test failed. Some example tests are the MD5 checksum test, file size, and modification times. The moral of the story is that RPM is an ally in finding out what is wrong with your system. If you want to verify all the packages installed on your system, type [root@fedora-serverA ~]# rpm -Va This command verifies all of the packages installed on your system. That’s a lot of files, so you might have to give it some time to complete.

⁠++++++++++++++++

⁠Package Validation

⁠++++++++++++++++

You might also have to import other vendors’ keys into the key ring. To be extra certain that even the local key you have is not a dud, you can import the key directly from the vendor’s web site. For instance, to import a key from Fedora’s project site, you would type [root@fedora-serverA ~]# rpm --import http://download.fedora.redhat.com/pub/⁠ fedora/linux/releases/9/Fedora/i386/os/RPM-GPG-KEY-fedora

⁠++++++++++++++++++++

⁠Software management with Yum

⁠++++++++++++++++++++

Yum is one of the newer methods of software management on Linux systems. It is basically a wrapper program for RPM, with great enhancements. It has been around for a while, but it has become more widely used and more prominent because major Linux vendors decided to concentrate on their (more profitable) commercial product offerings. Yum has changed and enhanced the traditional approach to package management on RPM-based systems. Popular large sites that serve as repositories for open source software have had to retool slightly to accommodate “Yumified” repositories. According to the Yum project’s web page: “Yum is an automatic updater and package installer/remover for RPM systems. It automatically computes dependencies and figures out what things should occur to install packages. It makes it easier to maintain groups of machines without having to manually update each one using RPM.” This summary is an understatement. Yum can do a lot beyond that. There are certain new Linux distributions that rely heavily on the capabilities provided by Yum. Using Yum is simple on supported systems. You mostly need a single configuration file (/etc/yum.conf). Other configuration files may be stored under the /etc/yum.repos.d/ directory that points to the Yum-enabled (Yumified) software repository. Fortunately, several Linux distributions now ship with Yum already installed and preconfigured. Fedora is one of these distros. To use Yum on a Fedora system (or any other Red Hat–like distro)—to install a package called gcc, for example—at the command line, you would type [root@fedora-serverA ~]# yum install gcc Yum will automatically take care of any dependencies that the package might need and install the package for you. (The first time it is run, it will build up its local cache.) Yum also has extensive search capabilities that will help you find a package, even if you don’t know its correct name. All you need to know is part of the name. For example, if you wanted to search for all packages that have the word “headers” in the name, you can try a Yum option like this: [root@fedora-serverA ~]# yum search headers This will return a long list of matches. You can then look through the list and pick the package you want. NOTE By default, Yum tries to access repositories that are located somewhere on the Internet. Therefore, your system needs to be able to access the Internet to use Yum in its default state.

Tag Summary

No tags have been pushed to this repository yet.