46

I have one server with net connectivity, where I can use "yum install $PACKAGE".
I want some yum command, like yum cache-rpms $PACKAGE $DIRECTORY such that all required RPM files will be downloaded to $DIRECTORY, which will also have a file (Install.sh) stating the order in which to install these RPMs, on many other servers without net connectivity.
Install.sh may even be a shell script, which has the same behaviour as yum install $PACKAGE, except that it will not use the network, but will only use $DIRECTORY.

Possible?

I am looking for a general solution where yum and RPM is available, but for specificity: It is on a set of CENTOS 6.7 servers.

3
  • I can think of a couple of solutions-- which works better for you? (1) The single package approach. This downloads less, but requires more manual work. Or... (2) The whole repo approach. This downloads lots, but can be done with more automation. Feb 4, 2016 at 0:27
  • @SteveBonds , I would like (1) "single package", because (2) "whole repo" will take time to download and consume too much space.
    – Prem
    Feb 4, 2016 at 3:10
  • Have you looked at Spacewalk?
    – fpmurphy
    Feb 6, 2016 at 1:03

3 Answers 3

57

Here's a specific example using "httpd" as the package to download and install. This process was tested on both CentOS6 and CentOS7.

Install the stuff you need and make a place to put the downloaded RPMs:

# yum install yum-plugin-downloadonly yum-utils createrepo
# mkdir /var/tmp/httpd
# mkdir /var/tmp/httpd-installroot

Download the RPMs. This uses the installroot trick suggested here to force a full download of all dependencies since nothing is installed in that empty root. Yum will create some metadata in there, but we're going to throw it all away. Note that for CentOS7 releasever would be "7".

# yum install --downloadonly --installroot=/var/tmp/httpd-installroot --releasever=6 --downloaddir=/var/tmp/httpd httpd

Yes, that was the small version. You should have seen the size of the full-repo downloads!

Generate the metadata needed to turn our new pile of RPMs into a YUM repo and clean up the stuff we no longer need:

# createrepo --database /var/tmp/httpd
# rm -rf /var/tmp/httpd-installroot

Configure the download directory as a repo. Note that for CentOS7 the gpgkey would be named "7" instead of "6":

# vi /etc/yum.repos.d/offline-httpd.repo
[offline-httpd]
name=CentOS-$releasever - httpd
baseurl=file:///var/tmp/httpd
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

To check the missing dependencies:

# repoclosure --repoid=offline-httpd

I haven't figured out why on CentOS7 this reports things like libssl.so.10(libssl.so.10)(64bit) missing from httpd-tools when openssl-libs-1.0.1e-51.el7_2.2.x86_64.rpm (the provider of that library) is clearly present in the directory. Still, if you see something obviously missing, this might be a good chance to go back and add it using the same yum install --downloadonly method above.

When offline or after copying the /var/tmp/httpd repo directory to the other server set up the repo there:

# vi /etc/yum.repos.d/offline-httpd.repo
[offline-httpd]
name=CentOS-$releasever - httpd
baseurl=file:///var/tmp/httpd
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
# yum --disablerepo=\* --enablerepo=offline-httpd install httpd

Hopefully no missing dependencies!

5
  • 4
    I tried following your guide to build the folder on CentOS 7 and install it on Red Hat 7, it all worked without errors
    – Piyin
    Jan 16, 2018 at 19:38
  • 1
    While the compatibility between the two OSes is good enough that things like that work, in order to ensure RedHat support, you should download RedHat software from RedHat's servers using a similar process. Jan 17, 2018 at 18:08
  • 1
    Yes, you're right. But in this case it was a close environment with network rules I couldn't alter. Like some say: "the customer is always right"
    – Piyin
    Jan 17, 2018 at 20:53
  • 1
    working very well in Centos 7, thanks ! Mar 21, 2018 at 18:00
  • that is if you have yum installed, but what if you don't ... 18 hours ago
12

I needed it several times, so I automated @Steve Bonds answer. Just be sure do define PKG as the package to install on both machines (Disclaimer: for CentOS 7. For CentOS 6, change the --releasever and CentOS-7 spot.

online machine

PKG=... # NAME OF THE PACKAGE TO INSTALL ON OFFLINE MACHINE
yum install --downloadonly --installroot=/tmp/$PKG-installroot --releasever=7 --downloaddir=/tmp/$PKG $PKG
createrepo --database /tmp/$PKG
rm -rf /tmp/$PKG-installroot
rsync -arv /tmp/$PKG/ [IP of the machine]:/tmp/$PKG

on offline machine:

PKG=... # NAME OF THE PACKAGE
echo "[offline-$PKG]
name=CentOS-\$releasever - $PKG
baseurl=file:///tmp/$PKG/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7" >  /etc/yum.repos.d/offline-$PKG.repo

# install package offline:
yum --disablerepo=\* --enablerepo=offline-$PKG install --nogpgcheck $PKG
2
  • 1
    You might want to add -y to the last command to confirm installation of packages when run in background.
    – RobDil
    Feb 11, 2019 at 11:22
  • It's great that you took it from a description to an automated process. Nice work! Mar 21, 2019 at 16:18
5

Seems you're asking for yumdownloader which is contained in the package yum-utils. There are already a few questions and answers about this, see e.g. Download all dependencies with yumdownloader, even if already installed? or How do I find package URLs with Yum?

yumdownloader will download the packages, although it will not generate a file Install.sh as the order can be determined by yum itself, so you can install the packages on the target box via
yum install ./*rpm in the folder with your downloaded packages (which needs to include all dependencies compared to a base installation - see the first link above regarding repotrack)

1
  • +1 , Sounds like what I want ! I will experiment and update if it matches what I want !
    – Prem
    Feb 5, 2016 at 4:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .