Create Your Own Repository and Tell yum to Use IT

In case you need to install some packages on an offline RHEL Linux machine and you want to avoid having to manually resolve all the dependencies, you could follow these instructions:

  1. install the same linux version on a similar machine (or a VM) and allow it to connect to the internet. The computer should be similar in build platform, so that the packages downloaded for it are compatible with the destination machine.
  2. on the machine, use following command to download the needed packages:
    sudo yum install --downloadonly --downloaddir=/home/[your-user]/packages XXXX
    where XXXX is the package(s) you want to install on the offline machine.
    you can also use a similar command to download the updates:
    sudo yum update --downloadonly --downloaddir=/home/[your-user]/packages
  3. download and install createrepo_c (usually it can be installed using yum).
  4. now, you can use createrepo_c to create a local repository:
    createrepo_c --update /home/[your-user]/packages
    using --update option makes sure that the repository is updated instead of created from scratch. if not used, it overwrites any previous repodata you created. this is useful when you realize you have forgotten a package and need to recreate your repodata.
  5. you can check the list of packages inside your repo by using
    sudo yum repo-pkgs --repofrompath="[YourRepoName]",/home/[your-user]/packages [YourRepoName] list ([ref: yum-cheat-sheet])
    this should list all the available packages in your local repo.
  6. now, copy the folder /home/[your-user]/packages to your offline device and put it in /home/[path-on-offline-dev]/packages
  7. to install packages from your repository, use
    sudo yum install --nogpgcheck --repofrompath="[YourRepoName]",/home/[path-on-offline-dev]/packages XXXX
    or use the following command to update using yum:
    sudo yum update --nogpgcheck --repofrompath="[YourRepoName]",/home/[path-on-offline-dev/packages
    don’t forget to use --nogpgcheck option to let yum install packages from your repository, otherwise yum will complain that the gpg-check has failed because you do not have any gpg public keys installed.

What’s happening?

  • yum can download a package and its dependencies instead of installing them. this is done using --downloadonly option. the default download path might vary based on distribution, and the path may contain other packages which are not needed. therefore, using --downloaddir=/your/own/path you can ensure that the created repository only contains packages you wanted. [ref: download-yum-packages]
  • yum uses repositories in order to install packages and their dependencies. they are usually defined in files found in /etc/yum.repos.d/. it’s possible define custom repositories, like for example from an installation DVD/ ISO-file (please refer to [ref: iso-as-repository]). createrepo_c enables users to create a repository from downloaded packages. it can be called on any path containing the packages and will create the repository in that folder (under repodata).
  • in order to tell yum to use a locally defined repository instead of one defined in the repository list, --repofrompath="[RepoName]",/repo/path can be used [ref: howto-createrepo_c].
  • in order to update an existing repository with new packages, it’s important to use --update option with createrepo_c ([ref: createrepo_c-options]).

References:

  1. [ref: download-yum-packages] https://ostechnix.com/download-rpm-package-dependencies-centos/
  2. [ref: iso-as-repository] https://access.redhat.com/solutions/1355683
  3. [ref: yum-cheat-sheet] https://access.redhat.com/sites/default/files/attachments/rh_yum_cheatsheet_1214_jcs_print-1.pdf
  4. [ref: howto-createrepo_c] https://unix.stackexchange.com/a/393997
  5. [ref: createrepo_c-options] https://www.mankier.com/8/createrepo_c#Options—update

Leave a Reply

Your email address will not be published. Required fields are marked *