skip to Main Content

First time asking a question in stackoverflow, and sorry if my english is bad, but hope someone can help me:

So, a project is using:

ruby '2.4.2'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.2.0'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'

Have used the correct ruby version with rbenv, but when running bundle install, I encountered:

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/pg-1.2.3/ext
/Users/USERNAME/.rbenv/versions/2.4.2/bin/ruby -I /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0 -r
./siteconf20221031-24074-1i63oht.rb extconf.rb --with-pg-config=/opt/homebrew/opt/libpq/bin/pg_config
Using config values from /opt/homebrew/opt/libpq/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 ***
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.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/Users/justinusjj/.rbenv/versions/2.4.2/bin/$(RUBY_BASE_NAME)
        --with-pg
        --without-pg
        --enable-windows-cross
        --disable-windows-cross
        --with-pg-config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib
        --with-pqlib
        --without-pqlib
        --with-libpqlib
        --without-libpqlib
        --with-ms/libpqlib
        --without-ms/libpqlib

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

  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-22/2.4.0/pg-1.2.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/pg-1.2.3 for inspection.
Results logged to /Users/USERNAME.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-22/2.4.0/pg-1.2.3/gem_make.out

  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0/rubygems/ext/builder.rb:90:in `run'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0/rubygems/ext/ext_conf_builder.rb:48:in `block in build'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/2.4.0/tempfile.rb:295:in `open'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0/rubygems/ext/ext_conf_builder.rb:28:in `build'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0/rubygems/ext/builder.rb:156:in `build_extension'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0/rubygems/ext/builder.rb:190:in `block in build_extensions'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0/rubygems/ext/builder.rb:187:in `each'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0/rubygems/ext/builder.rb:187:in `build_extensions'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/site_ruby/2.4.0/rubygems/installer.rb:821:in `build_extensions'
/Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/rubygems_gem_installer.rb:72:in
`build_extensions'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/source/rubygems.rb:207:in `install'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/installer/gem_installer.rb:54:in `install'
/Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/installer/parallel_installer.rb:186:in
`do_install'
/Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/installer/parallel_installer.rb:177:in `block
in worker_pool'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/worker.rb:62:in `apply_func'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/worker.rb:57:in `block in process_queue'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/worker.rb:54:in `loop'
  /Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/worker.rb:54:in `process_queue'
/Users/USERNAME/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-2.3.24/lib/bundler/worker.rb:91:in `block (2 levels) in
create_threads'

An error occurred while installing pg (1.2.3), and Bundler cannot continue.

In Gemfile:
  pg

Edit 1:
Tried brew install libpq then bundle install again, but failed with same error.

Edit 2:
Tried gem install pg -v 1.2.3 -- --with-pg-config=/opt/homebrew/bin/pg_config also failed with same error.

Edit 3:
Tried bundle config build.pg --with-pg-config=/opt/homebrew/opt/libpq/bin/pg_config then bundle install also failed with same error.

Edit 4:
Tried sudo env ARCHFLAGS="-arch x86_64" gem install pg -v 1.2.3 -- --with-pg-config=/opt/local/lib/postgresql@14/bin/pg_config also failed with the same error.

2

Answers


  1. Chosen as BEST ANSWER

    So.. been a few days but I didn't find a solution for this, maybe because the rails version is too old or incompatible with the Apple Silicon chip.

    But my senior did a work-around(?) by setting up this project with docker so it can be runned locally on my mac.

    Edit: The one who set it up with docker wasn't me but a senior in my workplace


  2. Same problem. Resolved by reinstalling xcode command-line tools:

    sudo rm -rf /Library/Developer/CommandLineTools
    
    xcode-select --install
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search