Homebrew is a package manager of OSX that makes installing tools and libraries a breeze.
The installation of the tools is explained in detail on the website.
If you want to get started right ahead drop the following line in your terminal:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"