This information comes from a blog post I wrote some time ago.
First, create a Virtual Machine and do a fresh install of the same RHEL version on it. Make sure you perform a minimal installation so that the packages installed on the machine are kept to the minimum required for the machine to run.
Then, run the following commands on the machine:
[vm]# mkdir /root/tmppkg
[vm]# yum --downloadonly --downloaddir=/root/tmppkg install foobar
Yum will download Foobar and all its dependencies recursively, storing the RPMs in the directory mentioned above.
Create a repository from the bunch of packages downloaded by Yum.
[vm]# chown -R root:root /root/tmppkg
[vm]# createrepo /root/tmppkg
[vm]# chmod -R 755 /root/tmppkg
tmppkg directory on the server (via USB thumb drive or CD-ROM) and put it in the
/share directory. Then create a file
/etc/yum.repos.d/local.repo as such:
Now you can install the Foobar package on the server in the usual way. The package manager will fetch all the necessary content from the newly created local repository:
[server]# yum install foobar
Once you’ve installed the package, the
/share/tmppkg directory can be safely deleted.