Centos – How to install packages offline

centoscentos7yum

Our server runs offline and we need to install lot of yum packages, like oracle-jdk, elasticsearch, nginx, etc.

Is there any way to download the rpm dependencies so we can install them offline in the server?

Best Answer

Maintain a local CentOS mirror on an Internet-connected machine with rsync to a public CentOS mirror that accepts rsync connections. You can then copy these directories to a USB stick and use them as installation sources. They already carry the necessary metadata to act as repositories, so you only need to point the installer at them.

$ du -sh /srv/www/mirrors/centos/7.1.1503/{os,updates}/x86_64 
7.1G    /srv/www/mirrors/centos/7.1.1503/os/x86_64
2.1G    /srv/www/mirrors/centos/7.1.1503/updates/x86_64

In the case of third party packages, you can also mirror those yourself using the reposync command line tool, which downloads the contents of yum repositories to a local filesystem, and createrepo, which creates a yum repository out of a set of RPMs in a directory.

Remember that repositories do not have to be on the network. They can be located on a local filesystem such as a hard drive, DVD-ROM or USB stick.