pg gem '0.14.0' on Mountain Lion fails

China☆狼群 提交于 2019-11-27 03:51:44

问题


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.

回答1:


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!




回答2:


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




回答3:


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.




回答4:


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 ***



回答5:


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




回答6:


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



回答7:


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




回答8:


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.




回答9:


Homebrew installed pg_ctl in /usr/local/bin/pg_ctl, so the command for me was:

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



回答10:


Fro those, who are using Kubuntu 13.04 and installed pg with one click tool, pg config is in other folder, so command:

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


来源:https://stackoverflow.com/questions/11711394/pg-gem-0-14-0-on-mountain-lion-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!