So, you need install a lib called 'libpq' on Mac OS before install PG gem. After this you can remove them. Command: brew install libpq
If you are using Debian, execute sudo apt-get install libpq-dev
*** If you don't use brew:
1. Install gem PG by the litle native app Postgres.app. To install access
https://postgresapp.com/. After installation, execute the and can close them.
$ gem install pg -v <gem version `0.20.0`> -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
Done!
PS.: To use PSQL, creates a symbolic link like bellow:
$ ln -s /Applications/Postgres.app/Contents/Versions/latest/bin/psql /usr/local/bin/psql
$ PGPASSWORD=<your-password> psql -h localhost -p 5432 -U postgres -c "\list"