Installing rpms offline using a local yum repository
If you have a CentOS 7 machine that does not have internet access, resolving dependencies when installing rpms can be tricky. Rather manually trying to resolve all dependencies (e.g. rpm -Uvh blah.rpm blah-dependency-1.rpm ...etc
), it is much simpler and more maintainable to create a local yum repository. Then, with only a couple of extra command line options, you can use yum to install dependencies from your local repository and let it resolve all the dependencies for you (e.g. yum --disablerepo=\* --enablerepo=offline-myrepo install blah
). This page documents how to achieve that.
Overview §
First from a CentOS 7 machine with internet access we create the local repository, and install all the packages we need into the local repository.
Then we copy the local repository across to the CentOS 7 machine which does not have internet access, and install the packages we need from that local repository into the machine.
Local repository requirements §
From the online machine, install these requirements which are needed for creating local repository:
Additional repositories (optional) §
EPEL §
Not all necessary packages are available on the default repositories.
Add the EPEL repository (Extra Packages for Enterprise Linux) to give access to many more pacakges:
nginx §
EPEL does not always have the latest versions. For example, currently the latest version of nginx it has is v1.12.2, whereas v1.14.0 is the current latest stable version of nginx. To ensure we can get v1.14.0, we add the nginx repository:
Now we can see which versions of nginx are available to us, and verify that v1.14.0 is present:
NodeJS §
To install NodeJS, add the following repository:
Python 3.6 §
Add IUS repository for Python 3.6:
Create local repository folders §
We will call our repository myrepo
. You can, of course, use another name:
Install to local repository §
Using yum §
Most packages can be installed into our local yum repository from the upstream yum repositories.
Install all required packages to our local myrepo
repository:
Manually §
Some rpms are not available in yum. For example MySQL rpms must be downloaded from the MySQL website.
Manually copy these in to /var/tmp/myrepo
:
Finalise the repository §
Generate the metadata to turn the folder of rpms into a yum repository:
Clean up (optional) §
This folder is no longer necessary:
Install from repository offline §
Now on the offline machine, copy the repository over (/var/tmp/myrepo
) and then add the following file to enable the repository:
We can now install dependencies from our offline yum repository, e.g. nodejs:
For nginx I found that it failed on the GPG check (which is presumably why the nginx documentation instructed us to set gpgcheck=0
in nginx.repo
earlier), but we can use the --nogpgcheck
option to disable that on an individual basis:
There you have it! No more manually specifying all rependencies on the offline machine, simply rely upon yum.
Modifying the repository §
If you need to modify the local repository, you will need to run createrepo
, but also need to run clean metadata
on the offline machine. For example:
This clean
command is necessary because yum caches the repository metadata. If you modify your offline repository (e.g. add a new rpm and then run createrepo
) yum will be unable to find it until you run the clean
command!