Download RPM packages for command which is already installed
I have a CentOS machine in which I already installed openssl-devel using
$ yum install openssl-devel
It downloaded and installed all the dependency packages. Now I need all those RPM packages. Is it possible to download only the RPM packages? When I do this:
$ yum install openssl-devel -y --downloadonly
It says
Package 1:openssl-devel-1.0.1e-4.fc18.x86_64 already installed and latest version
since it's already installed.
Does anyone know how to download those RPM packages on the same system?
Solution 1:
It is possible to download the packages of an RPM which is already installed using the --downloadonly
switch. I am not sure why yum doesn't check this setting before checking whether the package is already installed, but I guess it could be caused by the underlying architecture of the tool.
Anyway, all you need to do is to tell yum to reinstall the package:
yum --downloadonly --downloaddir=/tmp/rpm_files/ reinstall package_name
Of course, yum will not know which dependencies were installed just for this package, so if you take the RPMs and try to install them on a different system, some dependencies might be missing. There are ways to explore the whole dependency graph and I'm sure this was already described elsewhere on SE.
Solution 2:
yumdownloader
in yum-utils
will download any packages you pass to it, or optionally generate the URLs the packages can be downloaded from.
Solution 3:
You can use the repotrack command from the yum-utils package. It will download the entire dependency tree - even if it is already installed.
Example:
sudo yum install yum-utils # Install yum-utils
sudo repotrack openssl-devel # Download all dependencies for openssl-devel
Sample output:
[sbadra@rhel6 ~]$ sudo yum install openssl-devel
Loaded plugins: product-id, search-disabled-repos, subscription-manager
Setting up Install Process
Package openssl-devel-1.0.1e-57.el6.x86_64 already installed and latest version
Nothing to do
[sbadra@rhel6 ~]$ sudo repotrack openssl-devel
Downloading audit-libs-2.4.5-6.el6.x86_64.rpm
Downloading audit-libs-2.4.5-6.el6.i686.rpm
Downloading basesystem-10.0-4.el6.noarch.rpm
Downloading bash-4.1.2-48.el6.x86_64.rpm
Downloading ca-certificates-2017.2.14-65.0.1.el6_9.noarch.rpm
Downloading chkconfig-1.3.49.5-1.el6.x86_64.rpm
Downloading coreutils-8.4-46.el6.x86_64.rpm
Downloading coreutils-libs-8.4-46.el6.x86_64.rpm
.... more packages ....
Downloading openssl-1.0.1e-57.el6.i686.rpm
Downloading openssl-1.0.1e-57.el6.x86_64.rpm
Downloading openssl-devel-1.0.1e-57.el6.i686.rpm
Downloading openssl-devel-1.0.1e-57.el6.x86_64.rpm
.... more packages ....
Downloading sed-4.2.1-10.el6.x86_64.rpm
Downloading setup-2.8.14-23.el6.noarch.rpm
Downloading tzdata-2018c-1.el6.noarch.rpm
Downloading zlib-1.2.3-29.el6.x86_64.rpm
Downloading zlib-1.2.3-29.el6.i686.rpm
Downloading zlib-devel-1.2.3-29.el6.i686.rpm
Downloading zlib-devel-1.2.3-29.el6.x86_64.rpm
Solution 4:
One possibility in the longer term might be to designate a machine as the one to download from the internet, then run NFS (or a webserver) on it to expose /var/cache/yum to the internal hosts.
You would then need to update your yum config, to add:
[main]
keepcache = 1
Per https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/sec-Working_with_Yum_Cache.html:
Once you enabled caching, every yum operation may download package data from the configured repositories.
In more practical terms:
$ sudo yum install -y nginx
$ sudo find /var/cache/yum/ -type f -name '*.rpm'
<...snip....>
/var/cache/yum/x86_64/7/epel/packages/nginx-1.10.2-1.el7.x86_64.rpm
The other answers will actually solve your immediate issue, where this will only help if you run yum reinstall
for the packages you already have, and want RPMs for.