Just shut down both machine, remove the memory (RAM) from both machines and just swap them over.

The memory does not hold any of the OS, that is stored on the Hard Drive and is not involved in the changing out of the memory. Your OS will be there when you start up the machine again, assuming you do no damage when changing out the memory.

A word of caution. The memory is in the base of this iMac and to access it you need to remove the bottom cover.
To access the bottom you will need to lay the iMac down. I found that a pillow will provide the necessary support for the screen and allow the base to stand vertically.

Have you changed out this type of memory before? It is basically Laptop type memory and not like you see in a full size Mac or PC.