How to use yum to download a package without installing it

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) 7
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 5

Issue

  • How do I use yum to download a package without installing it?

Resolution

There are two ways to download a package without installing it.

One is using the "downloadonly" plugin for yum, the other is using "yumdownloader" utility.

Downloadonly plugin for yum

  1. Install the package including "downloadonly" plugin:

    (RHEL5)
    # yum install yum-downloadonly
    
    (RHEL6)
    # yum install yum-plugin-downloadonly
    
  2. Run yum command with "--downloadonly" option as follows:

    # yum install --downloadonly --downloaddir=<directory> <package>
    
  3. Confirm the RPM files are available in the specified download directory.

Note:

  • Before using the plugin, check /etc/yum/pluginconf.d/downloadonly.conf to confirm that this plugin is "enabled=1"
  • This is applicable for "yum install/yum update" and not for "yum groupinstall". Use "yum groupinfo" to identify packages within a specific group.
  • If only the package name is specified, the latest available package is downloaded (such as sshd). Otherwise, you can specify the full package name and version (such as httpd-2.2.3-22.el5).
  • If you do not use the --downloaddir option, files are saved by default in /var/cache/yum/ in rhel-{arch}-channel/packages
  • If desired, you can download multiple packages on the same command.
  • You still need to re-download the repodata if the repodata expires before you re-use the cache. By default it takes two hours to expire.

Yumdownloader

If downloading a installed package, "yumdownloader" is useful.

  1. Install the yum-utils package:

    # yum install yum-utils
    
  2. Run the command followed by the desired package:

    # yumdownloader <package>
    

Note:

  • The package is saved in the current working directly by default; use the --destdir option to specify an alternate location.
  • Be sure to add --resolve if you need to download dependencies.
  • Component
  • yum

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

26 Comments

very useful information ..
ThankQ

You should mention that the yumdownloader utility is part of the yum-utils package, which is not installed by default (at least it wasn't installed by default on my RHEL-5 system.)

Added.

Thanks for your feedback David.

Thank you for the info. yes very useful

--JP

Is there is anyway to download all the packages of RHEL 6. I want to create a local repository.

ThaneDC if you need the question answered quickly I would suggest posting this on discussions (https://access.redhat.com/site/discussions) or even asking someone in support. Otherwise I'll try to have someone get back as soon as possible.

Hello ThaneDC Linux,

You can go to the Downloads section of the portal and, for each release you will fond a "Source" tab on the page where you download the binary ISO. Click on that tab and it will take you to a page where you can download the sources DVD. Here is the Red Hat Enterprise Linux 6 Update 5 page as an example.

https://access.redhat.com/downloads/content/69/ver=/rhel---6/6.5/x86_64/product-sources

HTH.

Downloading the ISOs will give you the latest release. You can copy the CD's contents to a web server and point a yum repo at the directories that contain a "repodata" subdirectory. For the RHEL7 DVD, that would be the disc's root directory, addons/HighAvailability and addonsa/ResilentStorage.

If you want a repo with updates, then there are two choices:

The first option is that you can install all of the packages on a single computer. Then edit /etc/yum.conf to set the "keepcache" option to 1, so packages won't be deleted after installation. You can copy all these packages to a common location and run "createrepo" (part of the yum-utils package) to make it into a repo that yum can use. Note that you can't actually install every package, because there are some contradictions, but there aren't many. If you want to delete redundant packages (e.g. if something has been updated more than once), you will have to do that by hand.

The second approach is to use the "reposync" utility (also from yum-utils) to mirror all the packages from RedHat repo to a local location (use "yum repolist" to get the correct name) and then use the "createrepo" utility to make a local repo from what you downloaded. This is probably easier than the first option, but you'll end up downloading everything, including packages from your installation DVD, which you might already have in a different repo.

Seconding the suggestion to use reposync. It's a really useful method that allows one to do chrooted yum installs to create an OS image (useful if you're looking to build custom AMIs in AWS).

Sorry for replying over a year later, but you can use the reposync and createrepo tools to mirror a repo.

RedHat even has an article about how to do this: https://access.redhat.com/solutions/23016

On RHEL 7 with the
and its dependencies installed, 'yumdownloader --resolve
' will only download
and no dependency packages. The message is

--> Running transaction check
---> Package
will be installed
--> Finished Dependency Resolution

If the
RPM is already in the destdir, the 'installed' becomes 're-installed'.

On RHEL7, yumdownloader fails with:

Repo rhel-7-server-rpms forced skip_if_unavailable=True due to: /etc/rhsm/ca/redhat-uep.pem
Repo rhel-7-server-rpms forced skip_if_unavailable=True due to: /etc/pki/entitlement/8289723133685784604-key.pem
Repo rhel-7-server-extras-rpms forced skip_if_unavailable=True due to: /etc/rhsm/ca/redhat-uep.pem
Repo rhel-7-server-extras-rpms forced skip_if_unavailable=True due to: /etc/pki/entitlement/8289723133685784604-key.pem
Repo rhel-7-server-debug-rpms forced skip_if_unavailable=True due to: /etc/rhsm/ca/redhat-uep.pem
Repo rhel-7-server-debug-rpms forced skip_if_unavailable=True due to: /etc/pki/entitlement/8289723133685784604-key.pem
Repo rhel-7-server-optional-rpms forced skip_if_unavailable=True due to: /etc/rhsm/ca/redhat-uep.pem
Repo rhel-7-server-optional-rpms forced skip_if_unavailable=True due to: /etc/pki/entitlement/8289723133685784604-key.pem

yum install --downloadonly

fails if your package is already installed on the host, but "reinstall" fails if it is not. So if you have a list of packages, some of which are installed and some of which are not, you're stuck installing them all on the host so that you can "reinstall" them all --downloadonly.

So this question isn't actually answered.

This is counterintuitive but... while in other environments, downloading alone is a nonpriviledged task, in RHEL, it requires access to the certificates which are protected against non-root users. So in redhat, there's no way to do this sort of build without root access and these tasks in specific, require root access.

Silly me.

I am unable to download the rpm using the plugin method if the package is already installed.
I get warning saying package already installed and latest version Nothing to do.

Dejan you can:
rpm -e [therpm] --justdb
yum install [therpm] --downloadonly

That doesn't work either.

There are apparently no commands which allow for downloading a list of rpms, (and dependencies), without installing them on the host machine first.

Actually, there several methods - all touched upon in this thread.

I download lists plus dependencies all the time when generating new AMIs. You just need to specify an alternate config file and an alternate install-root (the alternate config file is used when the various yum tools re-root to the alternate installe-root you specify).

Need steps for downloading centos rpm(s) on a RHEL server.

how can this be verified if the methods do not work on RHELL 7?

Hello I have very specific requirement.

I want to develop a local repository with all latest packages available in RHEL updates repositroy, Why I am saying "latest" here, because update repository has similar packages with different versions, I just want to download the latest among them to reduce the size of my repository on disk as well as to reduce the downloaded data. After downloading I can do the file name comparison, but it seems very basic operation, reposync should provide some flag. Any Help would be great.

For example...

-rwxrwxrwx. 1 vagrant vagrant 80173248 Jun 27 05:18 firefox-45.1.0-1.el7_2.x86_64.rpm

-rwxrwxrwx. 1 vagrant vagrant 80040684 Jun 27 05:18 firefox-45.1.1-1.el7_2.x86_64.rpm

-rwxrwxrwx. 1 vagrant vagrant 80047428 Jun 27 05:18 firefox-45.2.0-1.el7_2.x86_64.rpm

I just want to include the firefox-45.2.0-1.el7_2.x86_64.rpm in my local repository.

I guess --newest-only should work.

Not at all. It can't download installed packages. I installed createrepo in dcoker images centos: 7.6.1810 by executing the following commands:

Yum install-y -- download only -- download dir=/root/test createrepo

But it cannot get libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm

好难过!

Not at all. It can't download installed packages. I installed createrepo in dcoker images centos: 7.6.1810 by executing the following commands:

Yum install-y -- download only -- download dir=/root/test createrepo

But it cannot get libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm

好难过!

Not at all. It can't download installed packages. I installed createrepo in dcoker images centos: 7.6.1810 by executing the following commands:

Yum install-y -- download only -- download dir=/root/test createrepo

But it cannot get libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm

好难过!

Not at all. It can't download installed packages. I installed createrepo in dcoker images centos: 7.6.1810 by executing the following commands:

Yum install-y -- download only -- download dir=/root/test createrepo

But it cannot get libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm

好难过!

Not at all. It can't download installed packages. I installed createrepo in dcoker images centos: 7.6.1810 by executing the following commands:

Yum install-y -- download only -- download dir=/root/test createrepo

But it cannot get libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm

好难过!