usually creating RAM disks works with the following commands
hdid -nomount ram://
Returns e.g. /dev/disk2 Then I would format
@Glyph provided the best answer in a comment to the accepted answer, but it deserves its own answer:
diskutil partitionDisk $(hdiutil attach -nomount ram://$((2048*sizeInMB))) 1 GPTFormat APFS 'Ramdisk' '100%'
Change sizeInMB
to your desired size.
I've updated Glyph's answer to simplify the volume name a little.