PCIe gen 5 is for the PCIe slots and NVMe storage slots, but they’re backwards compatible; you can put a gen 3 component in a gen 5 slot and it will work at gen 3 speeds. Similarly, if you put a gen 5 component in a gen 4 slot, it will be limited to gen 4 speeds. Right now there’s very little appreciable difference between gen 4 and gen 5 unless you’re spending a lot of money on the component (GPU/storage). Another thing to note is that Gen 5 requires that both the CPU and motherboard support it; a CPU with gen 4 support in a gen 5 motherboard will limit all the slots to gen 4 speeds.
RAM is a totally different standard that must be matched exactly for what the motherboard has; if it’s a DDR5 motherboard then you have to use DDR5 RAM or it won’t even fit in the slots. You can get a PCIe gen 5 motherboard and just use gen 4 SSDs or GPUs, that’s perfectly fine and leaves you room to upgrade later.