Extract RPMs from a Linux system

I have a virtual machine I tested out and got an environment I’m looking for, I want to move it to a none virtual machine system (a computer that is running only linux). How would I best move all the packages to that system?

Is there a folder for where all the .rpms are stored I can copy to a USB? or a command I could redownload all the installed .rpms

You could look at outputs of:

rpm -qa
dnf list installed

that’s cool for listing the rpms installed but is there a way to automatically go through the list and download the RPMs for offline install?

rpm -qa > installed_rpms.txt

This will create a .txt list of rpms and their version

sudo dnf download --resolve $(cat installed_rpms.txt)

this will iterate the list and install all the packages

if you run into issues like me, I made a bash to skip any RPMs that are not found online

#!/bin/bash

# Create a directory to store downloaded RPMs
mkdir -p rpms_downloaded
cd rpms_downloaded

# Loop through each package in the list and attempt to download it
for pkg in $(cat ../installed_rpms.txt); do
    sudo dnf download --resolve $pkg || echo "Package $pkg could not be found and was skipped"
done

echo "Download completed. RPMs are stored in the rpms_downloaded directory."