How to use yum to download RPM package without installing

Method 1: yum

The yum command itself can be used to download an RPM package. The standard yum command provides the --downloadonly option for this purpose.

  1. $ sudo yum install --downloadonly <package-name> 

By default, a downloaded RPM package is saved in the following directory:

  1. /var/cache/yum/x86_64/[centos/fedora-version]/[repository]/packages 

The above [repository] represents the name of the source repository of the downloaded package (for example: base, fedora, updates)

If you want to download a package to a specified directory (eg /tmp):

  1. $ sudo yum install --downloadonly --downloaddir=/tmp <package-name> 

Note that if the downloaded package contains any unmet dependencies, yum will download all the dependencies, but none of them will be installed.

Another important thing is that on CentOS/RHEL 6 or earlier, you need to install a separate yum plugin (named yum-plugin-downloadonly) to use the --downloadonly command option:

  1. $ sudo yum install yum-plugin-downloadonly 

Without this plugin, you will get the following error when using yum:

  1. Command line error: no such option: --downloadonly

Method 2: Yumdownloader

Another way to download RPM packages is through a special package download tool -- yumdownloader. This tool is a subset of the yum toolkit, which contains a suite of helper tools for yum package management.

  1. $ sudo yum install yum-utils 

Download an RPM package:

  1. $ sudo yumdownloader <package-name> 

The downloaded package will be saved in the current directory. You need to use root privileges because yumdownloader will update the package index file during the download process. Unlike the yum command, any dependencies will not be downloaded.

Download the lsof example:

yumdownloader lsof --resolve --destdir=/data/mydepot/ #resolve download dependencies

http://ask.xmodulo.com/yum-download-rpm-package.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326846450&siteId=291194637