On Linux console it’s easy to get free memory with free -m. On Mac the utility is not directly available. The alternative is to fetch it from vm_stat.

Ruby port of free

Installation

There’s a great small Ruby script to do the job and display free memory in a simplistic form with a command free in a following few steps:

  1. Download free-memory.rb gist
  2. Copy it to a folder on your Mac, e.g. to /Applications/Utilities
  3. Create an alias for a free command by editing the bash profile in Terminal:

     $ nano ~/.bash_login
    

    At the end of the file, add

     alias free='ruby /Applications/Utilities/free-memory.rb'
    

    Make the change available

     $ source ~/.bash_login
    

You’re done. Type free and you’ll see something like 3.98G of 8.19G free.