Far too often I accomplish this by clicking on the apple icon on the menu bar, then click “About this Mac”, then just read from the popup window. This is perfectly fine and all, until one day I was given only a shell and I needed to get that info.
Well, here is how you can do it in command line:
sysctl -a | grep mem
Then look for hw.memsize in the list. The number is in byte size, so you will need to do some conversion in your head. For example, if you see hw.memsize = 12884901888, that’s actually 12 * 1024 * 1024 * 1024, which is 12Gb.