Skip to content

Instantly share code, notes, and snippets.

@alexandrule
Forked from tomholford/install_pg_gem.md
Created October 17, 2023 09:33
Show Gist options
  • Save alexandrule/013bfbbad42d0ca8e3f59c7e1bea1dea to your computer and use it in GitHub Desktop.
Save alexandrule/013bfbbad42d0ca8e3f59c7e1bea1dea to your computer and use it in GitHub Desktop.
Install postgresql gem `pg` on macOS

Installing pg gem on macOS

If you're trying to install the postgresql gem pg and it is failing with the following error message:

Installing pg 1.2.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: ~/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/pg-1.2.3/ext
~/.rbenv/versions/3.0.0/bin/ruby -I ~/.rbenv/versions/3.0.0/lib/ruby/3.0.0 -r ./siteconf20210125-97201-pycpo.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header

The following helped me resolve the issue without having to install the entire postgresql as recommended in the stop Stack Overflow post (already using it in a Docker container):

  1. brew install libpq
  2. gem install pg -- --with-pg-config=/usr/local/opt/libpq/bin/pg_config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment