Cannot install pg gem
Asked Answered
I

2

6

I finally managed to get the 'pg' gem install after spending hours trying to figure out why it's not working...

at the end I entered sudo env ARCHFLAGS="-arch x86_64" gem install pg -v 0.12.2 -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config which worked like a charm. But now I still have the same error when I try bundler - so I guess I didn't really solve the problem? Anyway, here's what bundle install is saying:

 Installing pg (0.12.2) 
    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

            /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb --with-pg-config=/usr/pgsql-9.2/bin/pg_config
    Using config values from /usr/pgsql-9.2/bin/pg_config
    sh: /usr/pgsql-9.2/bin/pg_config: No such file or directory
    sh: /usr/pgsql-9.2/bin/pg_config: No such file or directory
    checking for libpq-fe.h... yes
    checking for libpq/libpq-fs.h... yes
    checking for PQconnectdb() in -lpq... yes
    checking for PQconnectionUsedPassword()... yes
    checking for PQisthreadsafe()... yes
    checking for PQprepare()... yes
    checking for PQexecParams()... yes
    checking for PQescapeString()... yes
    checking for PQescapeStringConn()... yes
    checking for PQgetCancel()... yes
    checking for lo_create()... yes
    checking for pg_encoding_to_char()... yes
    checking for PQsetClientEncoding()... yes
    checking for rb_encdb_alias()... yes
    checking for rb_enc_alias()... yes
    checking for struct pgNotify.extra in libpq-fe.h... yes
    checking for unistd.h... yes
    checking for ruby/st.h... yes
    creating extconf.h
    creating Makefile

make
    compiling compat.c
    compiling pg.c
    pg.c: In function ‘pgconn_wait_for_notify’:
    pg.c:2117: warning: ‘rb_thread_select’ is deprecated (declared at /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1/ruby/intern.h:380)
    pg.c: In function ‘pgconn_block’:
    pg.c:2592: warning: format not a string literal and no format arguments
    pg.c:2598: warning: ‘rb_thread_select’ is deprecated (declared at /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/include/ruby-1.9.1/ruby/intern.h:380)
    pg.c:2607: warning: format not a string literal and no format arguments
    linking shared-object pg_ext.bundle
    ld: warning: directory not found for option '-L-Wl,-undefined,dynamic_lookup'
    Undefined symbols for architecture x86_64:

....

    ld: symbol(s) not found for architecture x86_64
    collect2: ld returned 1 exit status
    make: *** [pg_ext.bundle] Error 1

I think the problem is that bundler tries to install the gem using the pg_config from another postresql installation (which I had removed). Is there any way to ensure that bundler uses the right path?

Ideate answered 5/3, 2013 at 21:48 Comment(3)
Found the solution, I need to run bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config before I could run bundle installIdeate
Oh, good to know. I hardly use Bundler myself, but I'll add that to the README so it will hopefully help other people that use it.Table
Just for the sake of completeness - the path I mentioned is needed in combination with the Postgres AppIdeate
P
12

I was stuck on my bundle install for 3 days. Tried Everything like adding env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

I was able to see pg gem getting installed after this command but still it was not installing from bundle install, which was a pain because I dint know what to write in Gemfile except gem 'pg'

The thing which finally worked for me was to find that my pg_config was in /Library/PostgreSQL/9.3/bin/pg_config and by default the Gemfile bundle install looks in /usr/local/bin/pg_config

I just ran the following command and magic happened. bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

Phage answered 26/12, 2014 at 7:5 Comment(1)
Could not locate Gemfile or .bundle/ directory. thanks for the helpAlliteration
P
4

Some correction. For those who have installed postgres using homebrew.

1) write the following line in your ~/.bash_profile

export ARCHFLAGS="-arch x86_64"

2) restart console

3) execute following command

bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config (this has to be your pg config address, can differ for each depending on versions of postgres)

4) Install pg once locally by running this command

sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

5) bundle install

Phage answered 21/9, 2015 at 19:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.