An error occurred while installing pg (0.21.0), and Bundler cannot continue
I think you dont have postgres insatlled.
Try: brew install postgres
Actually this worked for me
sudo apt-get install libpq-dev ruby-dev
It required me to install two packages libpq-dev
and ruby-dev