I got same issue today. I followed message You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application. So installed libpq-dev and bundle rails app again and the error disappeared.

$ sudo apt-get install libpq-dev
$ bundle install

The real solution is, as correctly pointed out by Amit Patel, to install libpq-dev


Here is a workaround if you were unable to setup pg at you development machine. You can use sqlite in your local machine and pg in Heroku. Here is what you should have in your Gemfile

group :production do
  gem 'pg'
end

group :development, :test do
  gem 'sqlite3'
end

And use this command for installing bundle to ignore production gems:

bundle install --without production

Please keep in mind that not having same environment in production and development machines is not recommended.