简体   繁体   中英

pg gem '0.14.0' on Mountain Lion fails

I just upgraded from OS X Lion to OS X Mountain Lion. My rails environment for the most part stayed in tact.

The only steps I had to do to get things back to a good state was: - Install XCode 4.4 - Install XCode 4.4 Command Line Tools - Install gcc-4.2

So all that went well.

Here's the issue, almost all my gems install properly when I run bundle install except for one of the most important ones I need - the postgresql gem 'pg'.

And it specifically fails for versions above 0.12.2.

I'm using ruby 1.9.3p125.

I can successfully grab the 0.12.2 pg gem, and versions below, but they give me segmentation faults (I'm guessing because of the version of ruby I'm using).

So this leads me to believe that it's specific to the pg gem, and not my overall environment seeing as other gems install fine.

I also tried re-installing Postgresql to ensure my postgres environment is ok and seems good on that front.

Has anybody been able to install the 'pg' gem version 0.13.0 or above (and more preferrably 0.14.X)?

Here is my stack trace:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

    /Users/caseyli/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/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... 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 PQescapeLiteral()... yes
checking for PQescapeIdentifier()... yes
checking for PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for pg_char_to_encoding()... yes
checking for PQsetClientEncoding()... yes
checking for PQlibVersion()... yes
checking for PQping()... yes
checking for rb_encdb_alias()... yes
checking for rb_enc_alias()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
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 pg.c
pg.c: In function ‘pg_s_library_version’:
pg.c:273: warning: implicit declaration of function ‘PQlibVersion’
pg.c: In function ‘Init_pg_ext’:
pg.c:384: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:384: error: (Each undeclared identifier is reported only once
pg.c:384: error: for each function it appears in.)
pg.c:386: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:388: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:390: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1


Gem files will remain installed in /Users/caseyli/.rvm/gems/ruby-1.9.3-        p125@elliottfarmequipment/gems/pg-0.14.0 for inspection.

Deefour's comment got it! It was the way I installed PostgreSQL.

I use the PostgreSQL one-click installer which I'm guessing doesn't set up the libpq up properly for Mountain Lion.

Homebrew on the otherhand will build it properly for the OS.

After installing postgres through homebrew

brew install postgresql

I was able to install my gem no problem.

Thanks everybody!

The issue is the location of pg_config. If you use the one-click installer, it is in /Library/PostgreSQL/9.2/bin/pg_config, so this will build your gem just fine:

env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.2/bin/pg_config

I had the exact same issue; same stack trace as you've posted.

MRI 1.9.3-p286 / OS X 10.8.2 / Postgres 9.0.4 with homebrew.

I solved it by simply doing:

$ brew update
$ brew upgrade postgresql
$ bundle

Hope it works for someone else.

Reinstalling ruby fixed a similar issue I was having after upgrading to Mountain Lion

rvm reinstall 1.9.3

Note: also run the following as it seems the default version resets

rvm --default 1.9.3

For reference I posted the error I was seeing below

gem install pg
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with pg=/usr/local/Cellar/postgresql/9.1.4/bin
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***

Mac comes with an outdated prebuilt PostgreSQL client installation and pg_config file that comes with it conflicts with any new PostgreSQL server & client installations.

Installing ruby gem with a fully qualified file name of pg_config overrides default known location of pg_config and installation succeeds.

Current location of pg_config by one click installer by EnterpriseDB: /Library/PostgreSQL/bin/pg_config

This command finally worked for me.

CrashMX2$ gem install pg -- --with-pg-config=/Library/PostgreSQL/bin/pg_config

I have had the same problem but reinstalling postgresql with homebrew did not solve it. However, this command did it for me:

sudo env ARCHFLAGS="-arch x86_64" gem install pg

I was able to get it to work by installing the Postgres.app from Heroku and removing my existing postgresql installation. You can download the app here:

http://postgresapp.com/

brew remove postgresql

bundle install

If you didn't use brew, here's a link to more uninstall docs from Postgres.app

http://postgresapp.com/documentation#toc_16

I just got mine up and running via this ticket:

How can I pass a parameter for gem installation when I run bundle install?

bundle config build.pg --with-pg-config=/path/to/pg_config
bundle install

Like Matt, Ranjan, and Peter Mellett all say, you have to get the right pg_config location, and Mountain Lion comes with a different location that doesn't seem to play well with rubygems, so if you find your old version like

/Library/PostgreSQL/bin/pg_config

then you can set that in the bundle config before installing.

My situation was upgrading from Lion to Mountain Lion.

Homebrew在/usr/local/bin/pg_ctl安装了pg_ctl ,所以对我来说命令是:

env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_ctl

对于使用Kubuntu 13.04并使用一键式工具安装pg的用户,pg config位于其他文件夹中,因此命令:

gem install pg -- --with-pg-config=/opt/PostgreSQL/9.3/bin/pg_config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM