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:
$ yum install yum-plugin-downloadonly yum-utils createrepo
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:
$ sudo yum install epel-release
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:
$ vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
Now we can see which versions of nginx are available to us, and verify that v1.14.0 is present:
$ yum --showduplicates list nginx | expand
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.econdc.com
* epel: mirror.veriteknik.net.tr
* extras: mozart.ee.ic.ac.uk
* updates: mirror.clustered.net
Available Packages
nginx.x86_64 1:1.8.0-1.el7.ngx nginx
nginx.x86_64 1:1.8.1-1.el7.ngx nginx
nginx.x86_64 1:1.10.0-1.el7.ngx nginx
nginx.x86_64 1:1.10.1-1.el7.ngx nginx
nginx.x86_64 1:1.10.2-1.el7.ngx nginx
nginx.x86_64 1:1.10.3-1.el7.ngx nginx
nginx.x86_64 1:1.12.0-1.el7.ngx nginx
nginx.x86_64 1:1.12.1-1.el7.ngx nginx
nginx.x86_64 1:1.12.2-1.el7_4.ngx nginx
nginx.x86_64 1:1.12.2-2.el7 epel
nginx.x86_64 1:1.14.0-1.el7_4.ngx nginx
NodeJS §
To install NodeJS, add the following repository:
$ rpm -Uvh https://rpm.nodesource.com/pub_4.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm
Python 3.6 §
Add IUS repository for Python 3.6:
$ yum install https://centos7.iuscommunity.org/ius-release.rpm
Create local repository folders §
We will call our repository myrepo
. You can, of course, use another name:
$ mkdir /var/tmp/myrepo
$ mkdir /var/tmp/myrepo-installroot
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:
$ yum install --downloadonly --installroot=/var/tmp/myrepo-installroot --releasever=7 --downloaddir=/var/tmp/myrepo nginx-1.14.0-1.el7_4.ngx bzip2 fontconfig gcc gcc-c++ git nodejs python36u python36u-devel python36u-pip rabbitmq-server
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
:
mysql-community-client-5.7.12-1.el7.x86_64.rpm
mysql-community-devel-5.7.12-1.el7.x86_64.rpm
mysql-community-common-5.7.12-1.el7.x86_64.rpm
mysql-community-libs-5.7.12-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.12-1.el7.x86_64.rpm
mysql-community-server-5.7.12-1.el7.x86_64.rpm
Finalise the repository §
Generate the metadata to turn the folder of rpms into a yum repository:
$ createrepo --database /var/tmp/myrepo
Clean up (optional) §
This folder is no longer necessary:
$ rm -rf /var/tmp/myrepo-installroot
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:
$ vi /etc/yum.repos.d/offline-myrepo.repo
[offline-myrepo]
name=CentOS-$releasever - My Repository
baseurl=file:///var/tmp/myrepo
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
We can now install dependencies from our offline yum repository, e.g. nodejs:
$ yum --disablerepo=\* --enablerepo=offline-myrepo install 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:
$ yum --disablerepo=\* --enablerepo=offline-myrepo install nginx --nogpgcheck
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:
$ yum --disablerepo=\* --enablerepo=offline-myrepo clean metadata
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!