Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze Linux RPM and YUM package Management

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to analyze Linux RPM and YUM package management, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

precondition

In order to make the most effective use of the articles in this series, you should have basic knowledge of Linux and need to prepare a Linux system to practice the commands introduced in this article. Sometimes different versions of the program have different output formats, so the results you get may not always be the same as the listings and diagrams shown here, especially since many of the output is highly dependent on packages already installed on the system. Your own output may be very different, but you should be able to see important things in common.

Brief introduction to package Management

In the past, many Linux programs were distributed as source code, which users built into the required programs or assemblies; the source code came with the necessary man pages, configuration files, and so on. Today, most Linux distributors use pre-built programs or assemblies called packages, which are easy to install on distributions. In this article, learn about package management tools that help install, update, and delete packages. This paper mainly focuses on Red Hat Package Manager (RPM) developed by Red Hat and Yellowdog Updater Modified (YUM) originally developed by Duke University Physics Department to manage Red Hat Linux system.

From the user's point of view, basic package management functions are provided by commands. Linux developers have been working to make Linux easier to use, and they have developed other tools (including GUI tools) to complement the basic tools, which hides part of the complexity of the basic tools from the end user. In this article and in learning Linux,101:Debian package management, we focus on the basic tools, but we will also mention some other tools so that you can continue to study them.

RPM, YUM, and APT (for Debian systems) have many similarities. All of them can install and delete packages. Information about the installed package is saved in the database. They all have basic command-line functions and provide a more user-friendly interface through other tools. They can all get packages from Internet.

When you install a Linux system, you usually install many packages. This collection may be customized according to the purpose of the system, such as a server, desktop, or development workstation. Sometimes, you may need to install new packages to add new features, update existing packages, or even delete packages that are no longer needed or have been replaced by new packages. Let's take a look at how to accomplish these tasks and how to solve some related problems, such as finding a package that contains a command.

RPM

Red Hat introduced RPM in 1995. RPM is now the package management system used in Linux Standard Base (LSB). The rpm command options are divided into three groups:

Used to query and check packages

Used to install, upgrade, and delete packages

Used to perform other functions

In this article, we focus on the first two sets of command options. Information about other features can be found in the man page of RPM.

It should also be noted that rpm is the main command for manipulating RPM, and .rpm is the extension used by the RPM file. So "a rpm" or "so-and-so rpm" generally refers to an RPM file, while rpm usually refers to a command.

YUM

YUM adds automatic updates and package management to the RPM system, including dependency management. Like Debian Advanced Packaging Tool (APT), YUM uses repositories in addition to knowing the packages installed on the system. A repository is a collection of packages that can usually be accessed over a network connection.

Install the RPM package

Suppose you want to learn Lisp, and a colleague asks you to use the gcl command. You try entering gcl-- help, which gcl, or type gcl. However, if the system cannot find gcl, you may see output similar to listing 1.

Listing 1. No gcl command found

[ian@echidna ~] $gcl-- helpbash: gcl: command not found [ian@echidna ~] $which gcl/usr/bin/which: no gcl in (/ usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/ian/bin) [ian@echidna ~] $type gclbash: type: gcl: not found

You may ask your colleagues which package to install, or you may guess that the gcl command should be in the gcl package. This guess is often correct, but not always. We'll see how to find the right package later. Here, you need the gcl package. Assuming that you have downloaded or otherwise obtained a copy of this package, you can install it using the rpm command with the-I (for installation) option, as shown in listing 2.

Listing 2. Install gcl with rpm-- first attempt

[root@echidna] # rpm-I gcl-2.6.8-0.6.20090701cvs.fc12.x86_64.rpmerror: Failed dependencies:gcl-selinux is needed by gcl-2.6.8-0.6.20090701cvs.fc12.x86_64

The rpm command knows that this package has a dependency package, but it does not help you solve the dependency problem. You need to get the dependency package yourself, and then try again to see if there are any other dependency packages-repeat the process until all the dependencies are satisfied. The good news is that you can provide the rpm command with a list of packages to install, and if all dependencies are satisfied, it installs all packages in the correct order. Therefore, at least you don't have to install each package manually in the correct order.

If you have used Debian's APT, you may want to have the same functionality as the apt-get command, which looks for what you need (including dependency packages) and installs them. For RPM-based systems, YUM (Yellowdog Updater Modified) provides this functionality. Listing 3 shows how to install gcl and the required gcl-selinux packages using the yum command with the install option.

Listing 3. Install gcl using yum

[root@echidna ~] # yum install gclLoaded plugins: presto Refresh-packagekitSetting up Install ProcessResolving Dependencies-- > Running transaction check--- > Package gcl.x86_64 0vir 2.6.8-0.7.20100201cvs.fc12 set to be updated-- > Processing Dependency: gcl-selinux for package: gcl-2.6.8-0.7.20100201cvs.fc12.x86mm 64muri-> Running transaction check--- > Package gcl-selinux.x86_64 0vir 2.6.8-0.7.20100201cvs.fc12 set to be updated-- > Finished Dependency ResolutionDependencies Resolved= Package Arch Version Repository Size=Installing: gcl x86 * 64 2.6.8-0.7.20100201cvs.fc12 updates 6.3 MInstalling for dependencies: gcl-selinux x86 * 64 2.6.8-0.7.20100201cvs.fc12 updates 17 kTransaction Summary=Install 2 Package (s) Upgrade 0 Package (s) Total Download size: 6.4MInstalled size: 40 MIs this ok [y kB N]: yDownloading Packages:Setting up and reading Presto delta metadataupdates/prestodelta | 964 kB 00:01 Processing delta metadataPackage (s) data still to download: 6.4m (1Accord 2): gcl-2.6.8-0.7.20100201cvs.fc12.x86_64.rpm | 6.3MB 00:12 (2ap2): gcl-selinux-2.6.8-0.7.20100201cvs.fc12.x86_64.rpm | 17 kB 00:00- -Total 398 kB/s | 6.4 MB 00:16 Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Installing: gcl-selinux-2.6.8-0.7.20100201cvs.fc12.x86_64 1 Acer 2 Installing: gcl-2.6.8-0.7.20100201cvs.fc12.x86_64 2 Installed: gcl.x86_64 00.7.20100201cvs.fc12 Complete 2.6.8-0.7.20100201cvs.fc12 Dependency Installed: gcl-selinux.x86_64 0VR 2.6.8-0.7.20100201cvs.fc12 Complete!

The output in listing 3 shows that YUM found gcl.x86_64 0VOR 2.6.8-0.7.20100201cvs.fc12 and gcl-selinux.x86_64 0VR 2.6.8-0.7.20100201cvs.fc12 in the repository named "updates" (discussed in more detail later) and determined the total download size. After pressing "y" to agree, it downloads the two packages, installs the dependency packages, and finally installs gcl. Dependencies are discussed further later in this article.

The location of the package

In the previous section, you learned how to install the RPM package. But where does the bag come from? How does yum know where to download the package? The starting point is the / etc/yum.repos.d/ directory, which often contains several repo files. This is the default location for repo, but you can specify another location in the YUM configuration file (usually / etc/yum.conf). Listing 4 shows fedora-updates.repo, and we get the gcl from its corresponding location and install it on my Fedora 12 system.

A typical repo file is divided into three parts, one for general packages, one for debugging packages, and the last one for source code packages. Package copies of distributions can often be obtained from different locations (that is, mirrors). So the repo file tells yum where to find the latest list of images for each section. Note that the release level and machine architecture of the distribution are expressed as parameters, so for my x86 releases 64 Fedora 12 system, yum downloads the list from https://mirrors.fedoraproject.org/metalink?repo=updates-released-f12&arch=x86_64.

In addition to the repository location, the repo file indicates whether a repository is enabled and whether the downloaded package should be checked with GPG signatures.

Listing 4. Fedora-updates.repo

[ian@echidna ~] $cat / etc/yum.repos.d/fedora- updates.repos [updates] name=Fedora $releasever-$basearch-Updatesfailovermethod=priority#baseurl= http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearchenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch[updates-debuginfo]name=Fedora $releasever-$basearch-Updates-Debugfailovermethod=priority#baseurl= http://download.fedoraproject.org/pub/ Fedora/linux/updates/$releasever/$basearch/debug/mirrorlist= https://mirrors.fedoraproject.org/metalink?repo=updates-released-debug-f$releasever&arch=$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch[updates-source]name=Fedora $releasever-Updates Sourcefailovermethod=priority#baseurl= http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/SRPMS/mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-source-f$releasever&arch=$basearchenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

YUM and RPM use the local database to determine which packages are installed. The package metadata stored in the local database is obtained from the enabled repository. Although there is little need to worry about the local database, you can use the yum clean command to clear different parts of the locally stored information and use yum makecache to create information in the local database for the enabled repo. For example, if you modify the repo configuration, you may need to do so.

Delete RPM package

If you want to delete a package, you can use the remove option of yum or the-e option of rpm. The trial run of removing gcl using rpm-e is shown in listing 5. If you can delete this package, there will be no output.

Listing 5. Try to delete gcl

[root@echidna] # rpm-e-test gcl

Unlike deleting Debian packages using apt-get simulation, the RPM system does not maintain information about automatically installed packages, so it is not possible to try to delete to find out which dependent packages can also be deleted. However, if you specify multiple packages to delete in a single command, packages that do not have dependencies will be deleted before those that have dependencies.

Unlike the installation package, when you delete a package using rpm, you are not prompted before deleting the package. However, if you try to delete a package needed by another package, it will not perform the delete operation, and you will see the error message shown in listing 6.

Listing 6. Delete dependent packages with rpm

[root@echidna] # rpm-e gcl-selinuxerror: Failed dependencies:gcl-selinux is needed by (installed) gcl-2.6.8-0.7.20100201cvs.fc12.x86_64

If you use yum remove, a prompt is displayed after the transaction test is performed. If the package you are trying to delete is a dependency of other installed packages, YUM proposes to delete those packages and dependent packages, as shown in listing 7.

Listing 7. Delete dependent packages with yum

[root@echidna ~] # yum remove gcl-selinuxLoaded plugins: presto Refresh-packagekitSetting up Remove ProcessResolving Dependencies-- > Running transaction check--- > Package gcl-selinux.x86_64 0vir 2.6.8-0.7.20100201cvs.fc12 set to be erased-- > Processing Dependency: gcl-selinux for package: gcl-2.6.8-0.7.20100201cvs.fc12.x86mm 64muri-> Running transaction check--- > Package gcl.x86_64 0vir 2.6.8-0.7.20100201cvs.fc12 set to be erased-- > Finished Dependency ResolutionDependencies Resolved= Package Arch Version Repository Size=Removing: gcl-selinux x86 / 64 2.6.8-0.7.20100201cvs.fc12 @ updates 90 kRemoving for dependencies: gcl x86 / 64 2.6.8-0.7.20100201cvs.fc12 @ updates 40 MTransaction Summary=Remove 2 Package (s) Reinstall 0 Package (s) Downgrade 0 Package (s) Is this ok [ythumb N]: nExiting on user CommandComplete!

Upgrade the RPM package

Now that you know how to install and remove RPM, let's take a look at how to upgrade the RPM package to a higher level. You can use yum update to update the entire system, and you can specify a single package or wildcard. Listing 8 shows how to update all packages whose names start with "gr". Note that apostrophes are used here to prevent shell from expanding "*".

Listing 8. Use yum update to perform updates

[root@echidna ~] # yum update 'gr*'Loaded plugins: presto Refresh-packagekitSetting up Update ProcessResolving Dependencies-- > Running transaction check--- > Package grep.x86_64 0VV 2.6.3-1.fc12 set to be updated--- > Package groff.x86_64 0RU 1.18.1.4-20.fc12 set to be updated-- > Finished Dependency ResolutionDependencies Resolved= Package Arch Version Repository Size=Updating: grep x86mm 64 2.6.3 -1.fc12 updates 228k groff x86'64 1.18.1.4-20.fc12 updates 1.5 MTransaction Summary=Install 0 Package (s) Upgrade 2 Package (s) Total download size: 1.7 MIs this ok [y http://fedora.fastsoft.net/pub N]: yDownloading Packages:Setting up and reading Presto delta metadataProcessing delta metadataDownload delta size: 854k http://fedora.fastsoft.net/pub / linux/fedora/linux/updates/12/x86_64/drpms/grep-2.5.3-6.fc12_2.6.3-1.fc12.x86_64.drpm: [Errno 14] HTTP Error 404: http://fedora.fastsoft.net/pub/linux/fedora/linux/updates/12/x86_64/drpms/grep-2.5.3-6.fc12_2.6.3-1.fc12.x86_64.drpm Trying other mirror. (1 2): grep -2.5.3-6.fc12_2.6.3-1.fc12.x86_64.drpm | 214 kB 00:00 (2 18.fc12_1.18.1.4 2): groff-1.18.1.4-18.fc12_1.18.1.4-20.fc12.x86_64.drpm | 640 kB 00:00 Finishing rebuild of rpms From deltarpms | 1.7 MB 00:02 Presto reduced the update size by 52% (from 1.7m to 854k). Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Updating: grep-2.6.3-1.fc12.x86_64 1 take 4 Updating: groff-1.18 .1.4-20.fc12.x86_64 2 Cleanup 4 Cleanup: grep-2.5.3-6.fc12.x86_64 3 Updated 4 Cleanup: groff-1.18.1.4-18.fc12.x86_64 4 Updated: Grep.x86_64 0VOR 2.6.3-1.fc12 groff.x86_64 0RU 1.18.1.4-20.fc12 Complete!

If you know the location of the RPM files, or if you have downloaded them, you can also use the rpm command to perform the update. This is similar to installation, except that you use the-U or-F option instead of the-I option. The difference between the two options is that the-U option updates the existing package and installs it if it is not already installed, while the-F option only upgrades or refreshes the installed package. Therefore, the-U option is often used, especially if the command line contains a list of RPM. In this way, uninstalled packages will be installed and installed packages will be upgraded. The other two options-v (detailed) and-h (# flag) are often used to provide a progress display. Listing 9 shows how to update the vim-common, vim-enhanced, and vim-minimal packages using the rpm command. We have downloaded the vim-common and vim-enhanced packages to the root user's home directory, while the vim-minimal packages are obtained from an update image.

Listing 9. Update packages with rpm

[root@echidna ~] # ls * .rpmvim-common-7.2.411-1.fc12.x86_64.rpm vim-enhanced-7.2.411-1.fc12.x8664.rpm [root @ echidna ~] # rpm-Uvh * .rpm http://mirrors.usc.edu/pub/linux/distributions\> / fedora/linux/updates/12/x86_64/vim-minimal-7.2.411-1.fc12.x86_64.rpmRetrieving http://mirrors.usc.edu/ Pub/linux/distributions/fedora/linux/updates/12/x86_64/vim-minimal-7.2.411-1.fc12.x86mm 64.rpm recording. # [100%] 1:vim-common # [33%] 2:vim-enhanced # # # [67%] 3:vim-minimal # [100%]

Query RPM package

As you saw in the previous example, installing rpm with the rpm command requires the full name (or URL) of the package file, such as gcl-2.6.8-0.6.20090701cvs.fc12.x86_64.rpm. On the other hand, using yum to install or remove rpm with these two commands requires only the package name, such as gcl. Like APT, RPM maintains information about installed packages in the internal database, thus allowing installed packages to be manipulated using package names. In this section, take a look at some of the information you can get from the database using the-Q (for query) option of rpm or the associated yum query.

The basic query only checks whether the package has been installed, and if so, query the version. Add the-I option to get information about the package. Note that root authority is required to install, upgrade, or delete packages, but non-root users can also query the rpm database.

Listing 10. Display information about gcl

[ian@echidna ~] $yum list gclLoaded plugins: presto, refresh-packagekitInstalled Packagesgcl.x86_64 2.6.8-0.7.20100201cvs.fc12 @ updates [Ian @ echidna ~] $rpm-Q gclgcl-2.6.8-0.7.20100201cvs.fc12.x86_64 [ian@echidna ~] $yum info gclLoaded plugins: presto Refresh-packagekitInstalled PackagesName: gclArch: x86_64Version: 2.6.8Release: 0.7.20100201cvs.fc12Size: 40 MRepo: installedFrom repo: updatesSummary: GNU Common LispURL: http://www.gnu.org/software/gcl/License: GPL+ and LGPLv2+Description: GCL is a Common Lisp currently compliant with the ANSI standard. : Lisp compilation produces native code through the intermediary of: the system's C compiler, from which GCL derives efficient: performance and facile portability. Currently uses TCL/Tk as GUI. [ian@echidna ~] $rpm-qi gclName: gcl Relocations: (not relocatable) Version: 2.6.8 Vendor: Fedora ProjectRelease: 0.7.20100201cvs.fc12 Build Date: Tue 23 Mar 2010 03:20:36 PM EDTInstall Date: Wed 05 May 2010 01:01:34 PM EDT Build Host: x86-02 .phx2.fedoraproject.orgGroup: Development/Languages Source RPM: gcl-2.6.8-0.7.20100201cvs.fc12.src.rpmSize: 41667750 License: GPL+ and LGPLv2+Signature: RSA/8 Tue 23 Mar 2010 04:14:06 PM EDT, Key ID 9d1cc34857bbccbaPackager: Fedora ProjectURL: http://www.gnu.org/software/gcl/Summary: GNU Common LispDescription: GCL is a Common Lisp currently compliant with the ANSI standard. Lispcompilation produces native code through the intermediary of thesystem's C compiler, from which GCL derives efficient performance andfacile portability. Currently uses TCL/Tk as GUI.

A detailed listing shows some of the tags associated with the RPM package. Note that rpm and yum display different information in different formats. In this article, we all use the basic output provided by the standard command options. If you want to customize the query output using the rpm-- queryformat option, refer to the man page. If you want to know all the tags supported by your version of rpm, you should run rpm-- querytags.

As shown in listing 10, you can use yum to list the installed packages. You can also use it to list packages available for updates, packages that can be installed, and packages with other properties, such as obsolete packages or packages recently added to the repository. You can even use yum search packages. As you can see in listing 11, the texmacs package is not installed yet, but it can be obtained from the fedora repository. If you search for "texmacs", you will see four packages that mention it. It's easy to see why the TeXmacs* package was found. Use yum info pydot to find out why the pydot package was also found.

Listing 11. Search for "texmacs"

[ian@echidna ~] $yum list texmacsLoaded plugins: presto, refresh-packagekitAvailable PackagesTeXmacs.x86_64 1.0.7.2-2.fc12 fedora [ian@echidna ~] $yum search texmacsLoaded plugins: presto, refresh-packagekit== Matched: texmacs = = TeXmacs-devel.i686: Development files for TeXmacsTeXmacs-devel.x86_64: Development files for TeXmacsTeXmacs.x86_64: Structured wysiwyg scientific text editorpydot.noarch: Python interface to Graphviz's Dot language

For the following query examples, we mainly use rpm because it has more options. Many examples can also be done using yum, and yum has some features that the basic rpm options do not have.

RPM package and the files in it

Users often want to know which files are in a package, or which package a file comes from. Use the-ql option to list the files in the gcl package, as shown in listing 12. There are many files in this package, so only part of the output is given here.

Listing 12. Show files in the gcl package

[ian@echidna ~] $rpm-ql gcl/usr/bin/gcl/usr/lib/gcl-2.6.8/usr/lib/gcl-2.6.8/clcs/usr/lib/gcl-2.6.8/clcs/sys-proclaim.lisp/usr/lib/gcl-2.6.8/cmpnew/usr/lib/gcl-2.6.8/cmpnew/gcl_cmpmain.lsp/usr/lib/gcl-2.6.8/cmpnew/gcl_cmpopt.lsp/usr/ Lib/gcl-2.6.8/cmpnew/gcl_collectfn.lsp.../usr/share/info/gcl-tk.info.gz/usr/share/info/gcl.info-1.gz/usr/share/info/gcl.info-2.gz/usr/share/info/gcl.info-3.gz/usr/share/info/gcl.info-4.gz/usr/share/info/gcl.info-5.gz/usr/share/info/gcl.info-6.gz/usr / share/info/gcl.info-7.gz/usr/share/info/gcl.info-8.gz/usr/share/info/gcl.info-9.gz/usr/share/info/gcl.info.gz/usr/share/man/man1/gcl.1.gz

You can limit the listed files to configuration files by adding the-c option to the query. The-d option limits the output to a document file.

Query package files

The above package query command queries the RPM database for installed packages. If you have just downloaded a package and want to get similar information, you can use the-p (for package file) option in the query and specify the file name of the package (as when you installed the package). Listing 13 shows the information for the two vim packages downloaded earlier. We only run it as the root user because the file is in the root user's home directory. You can add other query options, such as listing files with-l and information with-I.

Listing 13. Displays package file information for two vim packages

[root@echidna] # rpm-qp * .rpmvim-common-7.2.411-1.fc12.x86_64vim-enhanced-7.2.411-1.fc12.x86_64

Query all installed packages

The-an option applies the query to all installed packages. This produces a lot of output, so you usually use one or more filters at the same time, such as sorting with sort, paging output with more or less, getting packages or file contents with wc, and searching for packages with uncertain names with grep. Listing 14 shows the following query:

A sorted list of all packages on the system

The number of all packages on the system

The number of all files in all packages on the system

The number of all documentation files installed with RPM

Search for all packages with "gcl" in the name (case sensitive)

Listing 14. Execute queries on all packages

[ian@echidna ~] $rpm-qa | sort | moreaalib-libs-1.4.0-0.18.rc5.fc12.x86_64abrt-1.0.8-2.fc12.x86_64abrt-addon-ccpp-1.0.8-2.fc12.x86_64abrt-addon-kerneloops-1.0.8-2.fc12.x86_64abrt-addon-python-1.0.8-2.fc12.x86_64abrt-desktop-1.0.8-2.fc12.x86_64abrt-gui -1.0.8-2.fc12.x86_64abrt-libs-1.0.8-2.fc12.x86_64abrt-plugin-bugzilla-1.0.8-2.fc12.x86_64abrt-plugin-logger-1.0.8-2.fc12.x86_64abrt-plugin-runapp-1.0.8-2.fc12.x86_64abyssinica-fonts-1.0-5.fc12.noarchacl-2.2.49-2.fc12.x8664. [Ian @ echidna ~] $ Rpm-qa | wc-l1792 [ian@echidna ~] $rpm-qal | wc-l281052 [ian@echidna ~] $rpm-qad | wc-l45686 [ian@echidna ~] $rpm-qa | grep-I gclgcl-selinux-2.6.8-0.7.20100201cvs.fc12.x86_64gcl-2.6.8-0.7.20100201cvs.fc12.x86_64

Using rpm-qa can simplify the management of multiple systems. If you redirect the sorted output to a file on one machine, and then do the same on another machine, you can use the diff program to look for differences.

Which package contains a file?

Now that you can list all the packages and all the files in one package, you now have all the information you need to find out which package contains a file. However, the-f (or-- file) option of the rpm command can help find the package that contains a file. Suppose you want to know which vim package you saw earlier provides the vim command. You need the full path to the file. Listing 15 shows how to use the which command to get the full path of the vim command, which you can use as input to the rpm-qf command. Note that the symbol before and after `which guile- config` is an apostrophe. Another way to use it in Bash shell is $(which vim).

Listing 15. Which package provides vim executable files

[ian@echidna ~] $which vim/usr/bin/vim [ian@echidna ~] $rpm-qf `which vim`vim-enhanced-7.2.411-1.fc12.x86_64 [ian@echidna ~] $rpm-qf $(which vim) vim-enhanced-7.2.411-1.fc12.x86_64

RPM dependency relationship

You saw earlier that the operation to delete the gcl-selinux package failed because of the dependency. In addition to files, the RPM package may contain any functionality that other packages depend on.

As you can see, dependencies usually work properly. If you need to install several packages at the same time, some of which depend on others, simply use yum, or provide a complete list to the rpm-Uvh command, which analyzes the dependencies and performs the installation in the correct order.

In addition to the error messages generated when installing or removing a package, there are several ways to identify the files or features that the package needs or depends on.

The rpm command provides an option to query installed packages or package files to find out what features they depend on or require. This option is-- requires, which can be abbreviated to-R. Listing 16 shows the functionality required by gcl. If you want to query the package file instead of the RPM database, add the-p option and use the full RPM file name.

Listing 16. What gcl needs

[ian@echidna] $rpm-qR gcl/bin/sh / sbin/install-info / sbin/install-info gcl-selinux libX11.so.6 () (64bit) libc.so.6 () (64bit) libc.so.6 (GLIBC_2.11) (64bit) libc.so.6 (GLIBC_2.2.5) (64bit) libc.so.6 (GLIBC_2.3) (64bit) libc.so.6 ( GLIBC_2.3.4) (64bit) libc.so.6 (GLIBC_2.4) (64bit) libc.so.6 (GLIBC_2.7) (64bit) libc.so.6 (GLIBC_2.8) (64bit) libdl.so.2 () (64bit) libgmp.so.3 () (64bit) libm.so.6 () (64bit) libm.so.6 (GLIBC_2.2.5) (64bit) libreadline.so.6 () ) libtcl8.5.so () (64bit) libtk8.5.so () (64bit) libz.so.1 () (64bit) rpmlib (CompressedFileNames) Finished Dependency ResolutionDependencies Resolved= Package Arch Version Repository Size=Reinstalling: vim-common x86 / 64 2 MTransaction Summary=Remove 7.2.411-1.fc12 updates 6.0 MTransaction Summary=Remove 0 Package (s) ) Reinstall 1 Package (s) Downgrade 0 Package (s) Total download size: 6.0MInstalled size: 17 MIs this ok [y Mvim-common-7.2.411 N]: yDownloading Packages:Setting up and reading Presto delta metadataupdates/prestodelta | 969 kB 00:00 Processing delta metadataPackage (s) data still to download: 6.0Mvim-common-7.2.411-1.fc12.x86_64.rpm | 6.0 MB 00:01 Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionWarning: RPMDB altered outside of yum. Installing: 2:vim-common-7.2.411-1.fc12.x86_64 1 1.fc12.x86_64 1 Installed: vim-common.x86_64 2 1.fc12.x86_64 7.2.411-1.fc12 Complete! [root@echidna ~] # rpm-V vim-common [root@echidna ~] # ls / usr/bin/xxd/usr/bin/xxd

If stronger measures are needed

Package management systems can usually recover packages. However, if you delete important files in the package and reinstall the package without deleting it will not solve the problem, you may need to delete the package before reinstalling. In this case, you may want to delete the existing copy and reinstall it, but you do not want to uninstall and reinstall all packages that depend on it. To do this, you can use the-- nodeps option of the rpm command to bypass dependency checking when deleting a package. In listing 24, the / usr/bin/xxd file in vim-common is deleted, and then demonstrates how to restore the package.

Listing 24. Update packages with rpm

[root@echidna ~] # rm / usr/bin/xxdrm: remove regular file `/ usr/bin/xxd'? Y [root@echidna ~] # # Oops! We needed that file [root@echidna] # rpm-Fvh vim-common-7.2.411-1.fc12.x86_64.rpm [root@echidna ~] # ls / usr/bin/xxdls: cannot access / usr/bin/xxd: No such file or directory [root@echidna ~] # # Oh! Freshening the package didn't replace the missing file [root@echidna] # rpm-e vim-commonerror: Failed dependencies:vim-common = 2RU 7.2.411-1.fc12 is needed by (installed) vim-enhanced-2:7.2.411-1.fc12.x86_64 [root@echidna ~] # # Can't remove vim-common because vim-enhanced needs it [root@echidna] # rpm-e-- nodeps vim-common [root@echidna ~] # # Bypassing the dependency check allowed removal [root@echidna] # rpm-Uvh vim-common-7.2.411-1.fc12.x86_64.rpm Preparing... # [100%] 1:vim-common # [root@echidna] # # Update (or Install) vim-common again [root@echidna ~] # ls / usr/bin/xxd/usr/bin/xxd [root@echidna ~] # And / usr/bin/xxd is back

Now, in the event of an accident or general update failure, you can update or fix it in several ways. Note that dependency checking can also be bypassed when installing RPM, but this is usually not a good practice.

Download RPM from the repository

Although yum automatically fetches packages from the repository, you may want to download and save RPM, such as to install them on unconnected systems, to check their contents, or for other reasons. You can use the yumdownloader command shown in listing 25. For our example, this package is already installed, so there is no package to download. If you have such packages, you can download them again using the-- resolve option.

Listing 25. Download the gcl package

[ian@echidna ~] $yumdownloader-- resolve gclLoaded plugins: presto Refresh-packagekitadobe-linux-i386 17 MB 17 0.7.20100201cvs.fc12 set to be updated---> Running transaction check--- > Package gcl.x86_64 0VOV 2.6.8-0.7.20100201cvs.fc12 set to be updated-- > Finished Dependency Resolutiongcl-2.6.8-0.7.20100201cvs.fc12.x86_64.rpm | 6.3 CPM 00:01

Use rpm2cpio

If you download a RPM and need to check its contents instead of installing it, you can use the rpm2cpio command to convert the contents to a cpio archive, and then use the cpio command to extract some or all of the files in the package. Listing 26 performs the transformation on the gcl-selinux package and then shows the extracted files (and directories). For more information about the rpm2cpio and cpio commands, see their man pages.

Listing 26. Using rpm2cpio to extract gcl-selinux package

[ian@echidna ~] $yumdownloader gcl-selinuxLoaded plugins: presto Refresh-packagekitgcl-selinux-2.6.8-0.7.20100201cvs.fc12.x86_64.rpm | 17 kB 00:00 [ian@echidna ~] $mkdir gcl-selinux [ian@echidna ~] $cd gcl-selinux [ian@echidna gcl-selinux] $rpm2cpio.. / gcl-selinux*.rpm | cpio-idv./usr/share/selinux/packages/gcl./usr/share/selinux/packages/gcl/gcl.pp182 blocks [ian@echidna gcl-selinux] $find ... / usr./usr/share./usr/share/selinux./usr/share/selinux/packages./usr/share/selinux/packages/gcl./usr/share/selinux/packages/gcl/gcl.pp

Looking for RPM

We saw earlier that YUM provides search capabilities to search for package descriptions and package names. If you need to find out which package contains a program that has not been installed, there are several ways:

You can guess the package that may contain it, download the package, but do not install it. After you get the package, you can query it.

You can search for Internet.

You can try the command-not-found feature described below.

If a RPM cannot be found through the system tool, you can find the RPM through the Rpmfind.Net server.

Command not found

If Bash shell searches for a command and does not find it, shell searches for the shell function command_not_found_handle. If the command_not_found_handle function exists, shell calls it with the original command and parameters, and the exit state of the function becomes the exit state of the shell. If this function is not defined, shell outputs an error message and returns the exit status 127. This function is often set in the system / etc/bash.bashrc file. Listing 27 shows how to search for the command-not-found feature and install it.

Listing 27. Find and install the command-not-found feature

[root@echidna ~] # yum search command-not-foundLoaded plugins: presto, refresh-packagekit== Matched: command-not-found = = PackageKit-command-not-found.x86_64: Ask the user to install command line: programs automaticallyYou have new mail in / var/spool/mail/root [root@echidna ~] # yum install PackageKit-command-not-found.x86_64Loaded plugins: presto Refresh-packagekitSetting up Install ProcessResolving Dependencies-- > Running transaction check--- > Package PackageKit-command-not-found.x86_64 0vir 0.5.7-2.fc12 set to be updated-- > Finished Dependency ResolutionDependencies Resolved==== Package Arch Version Repository Size====Installing: PackageKit-command-not-found x86 kTransaction Summary=Install 64 0.5.7-2.fc12 updates 102 kTransaction Summary=Install 1 Package (s) Upgrade 0 Package (s) Total download size: 102kInstalled size: 262kIs this ok [y 2.fc12.x86_64 N]: yDownloading Packages:Setting up and reading Presto delta metadataProcessing delta metadataPackage (s) data still to download: 102kPackageKit-command-not-found-0.5.7-2.fc12.x86_64.rpm | 102kB 00:00 Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction Installing: PackageKit-command-not-found-0.5.7-2.fc12.x86_64 1 / 1 Installed: PackageKit-command-not-found.x86_64 0vl 0.5.7-2.fc12 Complete!

Listing 28 shows how to define this function after installing PackageKit-command-not-found. If the function cannot perform a search, it simulates standard system behavior and returns 127.

Listing 28. Command_not_found_handle

[ian@echidna ~] $type command_not_found_handlecommand_not_found_handle is a functioncommand_not_found_handle () {runcnf=1; retval=127; [!-S / var/run/dbus/system_bus_socket] & & runcnf=0; [!-x / usr/sbin/packagekitd] & & runcnf=0; if [$runcnf-eq 1]; then / usr/libexec/pk-command-not-found $1; retval=$? Else echo "bash: $1: command not found"; fi; return $retval}

If you installed this feature before running gcl in listing 1, you might see the output shown in listing 29.

Listing 29. Try to run gcl after installing command_not_found_handle

[ian@echidna] $gclCommand not found. Install package 'gcl' to provide command' gcl'? [N/y]

Other tools

In addition to yum and rpm, publishers may provide other tools for installing packages from repositories or updating the entire system. These tools may be graphical or command-line tools, or both. For example:

YaST (SUSE)

Up2date (Red Hat)

Mandrake Software Management (Mandriva)

Typically, these tools handle multiple package updates automatically or semi-automatically. They may also provide the ability to display repository contents or search packages. See the release documentation for more information.

PackageKit

You can't talk about package installation without mentioning PackageKit, a system designed to install and update software more easily. Its intention is to unify all the software graphical tools used in different distributions. PackageKit uses a daemon activated by the system, which means that the daemon is activated only when needed. Packagekit has versions for Gnome (gnome-packagekit) and KDE (KPackageKit). The command-not-found function described above is also part of PackageKit. It includes commands pkcon (performing package management functions from the console) and pkmon (monitoring package set activity). It also contains graphical tools for adding software packages or updating systems. Figure 1 shows an example of the Software Update graphical interface.

Figure 1. Software Update graphical interface on Fedora 12 (Gnome)

In addition to what is discussed here, RPM and YUM package management systems have many features. This is the end of the introduction of this article, for a more in-depth understanding, you can refer to other articles and materials.

The above content is how to analyze Linux RPM and YUM package management. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report