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:
- 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.
- on the machine, use following command to download the needed packages:
sudo yum install --downloadonly --downloaddir=/home/[your-user]/packages XXXX
whereXXXXis 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 - download and install
createrepo_c(usually it can be installed usingyum). - now, you can use
createrepo_cto create a local repository:createrepo_c --update /home/[your-user]/packages
using--updateoption makes sure that the repository is updated instead of created from scratch. if not used, it overwrites any previousrepodatayou created. this is useful when you realize you have forgotten a package and need to recreate yourrepodata. - 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. - now, copy the folder
/home/[your-user]/packagesto your offline device and put it in/home/[path-on-offline-dev]/packages - 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 usingyum:sudo yum update --nogpgcheck --repofrompath="[YourRepoName]",/home/[path-on-offline-dev/packages
don’t forget to use--nogpgcheckoption to letyuminstall packages from your repository, otherwiseyumwill complain that the gpg-check has failed becauseyou do not have any gpg public keys installed.
What’s happening?
yumcan download a package and its dependencies instead of installing them. this is done using--downloadonlyoption. 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/pathyou can ensure that the created repository only contains packages you wanted. [ref: download-yum-packages]-
yumuses 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_cenables 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 (underrepodata). - in order to tell yum to use a locally defined repository instead of one defined in the repository list,
--repofrompath="[RepoName]",/repo/pathcan be used [ref: howto-createrepo_c]. - in order to update an existing repository with new packages, it’s important to use
--updateoption withcreaterepo_c([ref: createrepo_c-options]).
References:
- [ref: download-yum-packages] https://ostechnix.com/download-rpm-package-dependencies-centos/
- [ref: iso-as-repository] https://access.redhat.com/solutions/1355683
- [ref: yum-cheat-sheet] https://access.redhat.com/sites/default/files/attachments/rh_yum_cheatsheet_1214_jcs_print-1.pdf
- [ref: howto-createrepo_c] https://unix.stackexchange.com/a/393997
- [ref: createrepo_c-options] https://www.mankier.com/8/createrepo_c#Options—update