memory – Mac Book won’t install software

I just recently replaced the drive in my MacBook Pro and after partitioning the drive, formatting it correctly, and multiple attempts to install it just won’t complete the process. When going through the Command + R menu it will start to download OS Mountain Lion but when it’s almost finished it will give an error in the install log that says “Failed to verify InstallESD.dmg: hdiutil verify failed” and it will begin to download all over again. If I go through the Command+option+r menu it will try to download OS Catilina and when it’s almost finished it will give an error that says ” an error occurred when installing macOS Catalina”. I’ve read that both of these problems might be related to ram so I took both out and reinstalled them as somebody suggested and still no luck. I really just want to make sure that it’s the ram before I go and spend the money. Any ideas would be appreciated!