Search code examples
ruby-on-railspostgresqljruby

Postgres gem not installing


I have postgres 10.4 on my Mac OS X High Sierra and Rails 5.2, however when I try to install pg gem I get a gem building error. It says it cannot build the gem despite a successful confirmation of pg_config. I was hoping someone could look at the error and point me in the right direction?

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

current directory: /Users/cdougherty/.rvm/gems/jruby-9.1.13.0/gems/pg-1.0.0/ext
/Users/cdougherty/.rvm/rubies/jruby-9.1.13.0/bin/jruby -r ./siteconf20180523-76754-a2cdps.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
RuntimeError: The compiler failed to generate an executable file.
You have to install development tools first.

 try_do at /Users/cdougherty/.rvm/rubies/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:456
  try_link0 at /Users/cdougherty/.rvm/rubies/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:541
   try_link at /Users/cdougherty/.rvm/rubies/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:556
 <main> at extconf.rb:40
*** 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.

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/Users/cdougherty/.rvm/gems/jruby-9.1.13.0/extensions/universal-java-1.8/2.3.0/pg-1.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/cdougherty/.rvm/gems/jruby-9.1.13.0/gems/pg-1.0.0 for inspection.
Results logged to /Users/cdougherty/.rvm/gems/jruby-9.1.13.0/extensions/universal-java-1.8/2.3.0/pg-1.0.0/gem_make.out

Here is the cat from the mfmk log if it helps.

find_executable: checking for pg_config... -------------------- yes

" -o conftest -I/include/universal-java1.8 -I/Users/cdougherty/.rvm/rubies/jruby-9.1.13.0/lib/ruby/include/ruby/backward -I/Users/cdougherty/.rvm/rubies/jruby-9.1.13.0/lib/ruby/include -I. -I/usr/local/Cellar/postgresql/10.4/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE     -fPIC -DTARGET_RT_MAC_CFM=0  -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions  conftest.c  -L. -L/Users/cdougherty/.rvm/rubies/jruby-9.1.13.0/lib -L/usr/local/lib    -arch x86_64      "

checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <ruby.h>
4: int main(int argc, char **argv)
5: {
6:   return 0;
7: }
/* end */

Solution

  • you can not really install any native C gems on JRuby.

    there's usually platform specific versions (separate gem releases sharing the same name) e.g. if you check nokogiri you see several 1.8.2 versions.

    for pg there isn't a java platform release (yet in 1.0.0 - maybe in the future).

    the way you run Rails with JRuby has been to use gem 'activerecord-jdbc-adapter'

    but please do note that 5.2 isn't supported atm - maybe some work on master