This comes from a blog post I wrote some time ago.
You can have yum fetch all the packages and their dependencies on your VM, then create a repo from them which will then be used by your server.
Note that the VM should have just the minimal packages required for it to run; since you don't know what's installed on the server, you want yum to download as many dependencies as possible.
On the VM:
# mkdir /root/tmppkg
# yum --downloadonly --downloaddir=/root/tmppkg install <packages>
# chown -R root:root /root/tmppkg
# createrepo /root/tmppkg
# chmod -R 755 /root/tmppkg
tmppkg directory on the server, let's say in
Then create a file
/etc/yum.repos.d/local.repo on the server as such:
Now run on the server:
# yum install <packages>
and the packages will be installed from the local repo.
Once yum has finished, you can delete
/opt/tmppkg to save space.