gem install pg not working on Mac El Capitan
Asked Answered
E

3

8

I tried to install pg Gem on Mac El Capitan, but I always get this error:

    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/Users/ricardolopes/Developer/homebrew/bin/pg_config
    Using config values from /Users/ricardolopes/Developer/homebrew/bin/pg_config
    checking for libpq-fe.h... yes
    checking for libpq/libpq-fs.h... yes
    checking for pg_config_manual.h... yes
    checking for PQconnectdb() in -lpq... no
    checking for PQconnectdb() in -llibpq... no
    checking for PQconnectdb() in -lms/libpq... no
    Can't find the PostgreSQL client library (libpq)
    *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of necessary
    libraries and/or headers.  Check the mkmf.log file for more details.  You may
    need configuration options.

    Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
        --with-pg
        --without-pg
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/
        --with-pqlib
        --without-pqlib
        --with-libpqlib
        --without-libpqlib
        --with-ms/libpqlib
        --without-ms/libpqlib


    Gem files will remain installed in /Users/ricardolopes/Code/site-noticias/vendor/bundle/ruby/2.0.0/gems/pg-0.18.3 for inspection.
    Results logged to /Users/ricardolopes/Code/site-noticias/vendor/bundle/ruby/2.0.0/gems/pg-0.18.3/ext/gem_make.out
    An error occurred while installing pg (0.18.3), and Bundler cannot continue.
    Make sure that gem install pg -v '0.18.3' succeeds before bundling.

I also tried:

ARCHFLAGS="-arch x86_64" gem install pg

When I tried it I got:

    Building native extensions.  This could take a while...
    Successfully installed pg-0.18.3
    invalid options: -f fivefish
    (invalid options are ignored)
    Parsing documentation for pg-0.18.3
    Done installing documentation for pg after 3 seconds
    1 gem installed

But I run bundle install and get the same error posted in the beginning of this post.

I tried reinstall PostgresSQL from brew.

Exsanguinate answered 26/10, 2015 at 1:55 Comment(0)
G
2

This worked for me:
sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

Remember to change 9.4 to your postgres version, if different from 9.4.

Gamone answered 26/12, 2015 at 21:45 Comment(0)
N
5

Try this:

  • brew update
  • brew install postgresql
  • sudo gem install pg -v 'VERSION'
Nickelplate answered 29/10, 2015 at 18:19 Comment(3)
I have the same problem as the original post. I tried this, but it did not resolve the problem. I have tried everything I could find as well. And like the OP, I have tried updating and reinstalling from homebrew. No joy. This problem brings my project to a complete, indefinite halt.Ramakrishna
After i reinstall my computer, i have the same problem again. This worked for me on 10.11.2: sudo su and env ARCHFLAGS="-arch x86_64" gem install pg -v '0.18.1'Nickelplate
It works on Mac OS X 10.11.6 with Bundler version 1.12.5Skipjack
G
2

This worked for me:
sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config

Remember to change 9.4 to your postgres version, if different from 9.4.

Gamone answered 26/12, 2015 at 21:45 Comment(0)
C
-1

For a basic Rails app, you probably already have SQLite installed, but in your Gemfile, it probably has simply:

gem 'sqlite3'

Do you just need PostgreSQL for production? Make sure your Gemfile has it as follows:

group :production do gem 'pg' end

Also, make sure your Gemfile has SQLite just for development:

group :development do gem 'sqlite3' end

then try running bundle install.

Cravens answered 26/10, 2015 at 4:0 Comment(3)
You're probably right, but even adding sqlite3 to my development group, rails insist in install pg gem... # Use sqlite3 as the database for Active Record gem 'sqlite3', group: :development and did this also: group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' gem 'sqlite3' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end group :production do gem 'pg' gem 'rails_12factor' end with no success...Exsanguinate
This is not reccomended if you are trying to develop a 12 factor app because it makes the dev and prod environments divergent. 12factor.net/dev-prod-parityFilippo
@Filippo is right, you should never use different db engines for prod and dev, bad idea.Featherweight

© 2022 - 2024 — McMap. All rights reserved.