pg gem '0.14.0' on Mountain Lion fails - ruby-on-rails

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

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

Related

Install PG gem in OpenSUSE

283
65
I'm trying to install PostgreSQL's pg gem for Ruby.
I issued the following command:
gem install pg
I installed Ruby 1.9.2 using RVM.
The above command shows me the following error.
The error is :
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby extconf.rb
checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.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 ***
etc...
Somebody gave solution for Ubuntu users.
What about OpenSUSE Linux?
Thanks for advance.
For me this was the solution:
zypper in postgresql-server-devel
pg_config is part of postgresql-server-devel, if you install that
package then it should work on Tumbleweed at least.
Source: https://lists.opensuse.org/opensuse-factory/2019-03/msg00300.html
As per my search OpenSUSE linux has no package for client of Postgres, but as you have installed that it, that mean chances are the file pgsql.so is present in your system. How did you install it, I can see following which says it will install development libraries and client also
sudo zypper in postgresql postgresql-server postgresql-contrib
sudo zypper in postgresql-plperl postgresql-plpython postgresql-plctl
If this does not work then try to search in postgres installation path this file, locate file_name is easy to find files on different linux, but not sure it works in openSUSE it is part of mlocate package. If you find that file then symbol link it as per error, where error is searching this file.
If it is still not working, then you can use your Postgres directory in environment variable and try to install gem individually. To get postgres configuration use following command to see directories.
pg_config
Now try to install gem
PATH=$PATH:/Library/PostgreSQL/9.0/bin sudo gem install pg
On some system following command also resolve issue, so you can try it too
sudo gem install pg – --with-pg-config=/usr/local/pgsql/bin/pg_config

Error installing Postgres gem on Mac

Here's the error I get when I run gem install pg:
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20151004-5579-1t2l557.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/local/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 ***
If I run brew install postgres I get:
Warning: postgresql-9.4.4 already installed
Likewise, gem list shows pg (0.18.3) and a simple gem -v pg gives:
2.4.4
Running sudo ARCHFLAGS="-arch x86_64" gem install pg returns:
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 4 seconds
1 gem installed
But bundle install throws up this error:
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'm seeing this in mkmf.log, which I think could be the biggest clue:
ld: warning: ignoring file /opt/local/lib/postgresql93/libpq.dylib, file was built for x86_64 which is not the architecture being linked (i386): /opt/local/lib/postgresql93/libpq.dylib
Undefined symbols for architecture i386:
"_PQconnectdb", referenced from:
_t in conftest-fc6c12.o
ld: symbol(s) not found for architecture i386
Which is strange given file /opt/local/lib/postgresql93/libpq.dylib returns x86_64, not i386:
/opt/local/lib/postgresql93/libpq.dylib: Mach-O 64-bit dynamically linked shared library x86_64
This didn't work either:
sudo env ARCHFLAGS="-arch i386 -arch x86_64" gem install pg
It seems you're almost there, because sudo ARCHFLAGS="-arch x86_64" gem install pg works. Try setting ARCHFLAGS globally, so bundle also can see it:
$ export ARCHFLAGS="-arch x86_64"
$ bundle
I've been working through this issue since yesterday. I ended up uninstalling Postgres, homebrew, and starting from scratch. When trying to add the 'pg' gem to my Ruby on Rail project it kept failing. Digging through the output I kept seeing it try to link the i386 libraries. So I tried adding the flag:
--arch-flags='x86_64'
That didn't seem to have any impact.
Then I found one where it was set right after the 'sudo'. That seemed to do the trick.
THIS WORKED!!!!!!!!
sudo ARCHFLAGS="-arch x86_64" gem install pg -v '0.18.3' -- --with-pg-config=/usr/local/bin/pg_config --arch-flags='x86_64'
In the project I actually had to repeat the steps for some reason in the project directory. Then re-repeat them and upgrade to version 0.18.4.
After that I could run 'bundle' and everything was included correctly.
A couple of the answers here:
http://stackoverflow.com/questions/19625487/impossible-to-install-pg-gem-on-my-mac-with-mavericks
suggest specifying the postgresql configuration file when performing the gem install. It is older but might provide the way forward. Search for "Check you have pg_config in the installed brew", which explains how to find the correct filename.

Missing PG headers ( trying to install Postgres gem for Rails with Brew )

checking for libpq-fe.h... *** extconf.rb failed ***
Seems to be the issue, it's from this tail:
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/elephanttrip/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** 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.
My steps to reproduce this on a Mountain Lion Mac OS is :
brew install postgresql
env ARCHFLAGS="-arch x86_64" gem install pg
I've tried to pinpoint different pg_config's through my computer. The one in Brew's cellar, the one cp'd by Brew to /user/local, and another one that might have been from a previous download of it. None of them work.
UPDATE
Just tried to install without the config-options. And got an lol:
ruby extconf.rb --without-pg-config
checking for pg_config... yes
I started imagining that my issue had something to do with RVM as the bottom of the trace it said.. :
"You need to download development tools"
Then I did :
$ rvm autolibs enable
$ rvm requirements
Then I went ahead and just updated my ruby ( if you don't do this, then I recommend just reinstalling it your current one. I could not do this without autolibs enable ) :
$ rvm install ruby-2.0.0-p0
Boom! Solved!!!! (:D :D :D :D :D) x 1,000,000

How to get the EventMachine gem to compile on OSX Lion 10.8.2 with Xcode 4.5.1

I looked everywhere I can find but can't seem to find a solution to this.
I'm using Xcode 4.5.1 on Lion 10.8.2, and am trying to run bundle for a Rails project and it keeps jamming up on this. I'm using the Thin gem for Heroku.
Bolanos#Jeremys-Mac-mini ⦿-1.9.3 fishfarm $ sudo gem install eventmachine
Password:
Building native extensions. This could take a while...
ERROR: Error installing eventmachine:
ERROR: Failed to build gem native extension.
/Users/Bolanos/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... no
checking for __NR_inotify_init in sys/syscall.h... no
checking for writev() in sys/uio.h... yes
checking for rb_thread_check_ints()... yes
checking for rb_time_new()... yes
checking for sys/event.h... yes
checking for sys/queue.h... yes
creating Makefile
make
compiling binder.cpp
make: g++-4.2: No such file or directory
make: *** [binder.o] Error 1
Gem files will remain installed in /Users/Bolanos/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0 for inspection.
Results logged to /Users/Bolanos/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0/ext/gem_make.out
For now I'm having to do without Thin. Does anyone have a solution?
Also check for a symlink:
$ sudo ln -s /usr/bin/g++ /usr/bin/g++-4.2
You have to install the Command Line Tools package from developer.apple.com.
Also I was having troubles with the MacOSX10.6.sdk because some headers were missing there, so I installed the MacOSX10.5.sdk and all worked fine.
I had the exact error, and creating a new symlink for the missing resource /usr/bin/g++-4.2 worked for me.
In my setup I pointed at the location in Cellar:
/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
If none of the above work for you, I did
sudo ln -s /usr/bin/llvm-g++-4.2 /usr/bin/g++-4.2
and it worked like a charm. Running OS X 10.8.2.
You should have both:
Xcode command line tool: Detailed instructions for installation are in "How to install Xcode Command Line Tools".
Apple-gcc* compiler: I should mention that compiling with gcc48 and gcc49 fails. Therefore, installing apple-gcc42 (if you don't have) and choosing the compiler via MacPorts will solve the problem. You can see the installed gcc versions using:
port select --list gcc
You should see something like this where "mp-" stands for MacPorts own port:
Available versions for gcc:
apple-gcc42 (active)
current_saved
mp-gcc48
mp-gcc49
If you don't have "apple-gcc*" you may install it via:
port install apple-gcc42
after that chose the compiler:
port select --set gcc apple-gcc42
Now you may run:
gem install eventmachine
This should solve the problem of errors which arise during building gem native extensions on OSX.

Error while building bundle due to pg gem? [duplicate]

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

Resources