Problem installing Apple Silicon M1

2,466 views
Skip to first unread message

Tim

unread,
Jan 4, 2021, 2:38:41 PM1/4/21
to ruby-pg
Hello.

I'm with difficulty to install pg gem in my new MacBook Pro M1 (Apple Silicon).
I installed postgresql with homebrew and it's running successfully.
But when I try to install the pg gem I get this error:

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

    current directory: /Users/tim/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/pg-1.2.3/ext
/Users/tim/.rbenv/versions/2.7.1/bin/ruby -I /Users/tim/.rbenv/versions/2.7.1/lib/ruby/2.7.0 -r ./siteconf20210104-15657-13x7wqv.rb extconf.rb
checking for pg_config... yes
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/tim/.rbenv/versions/2.7.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pq-dir
--without-pq-dir
--with-pq-include
--without-pq-include=${pq-dir}/include
--with-pq-lib
--without-pq-lib=${pq-dir}/lib
--with-pqlib
--without-pqlib
--with-libpq-dir
--without-libpq-dir
--with-libpq-include
--without-libpq-include=${libpq-dir}/include
--with-libpq-lib
--without-libpq-lib=${libpq-dir}/lib
--with-libpqlib
--without-libpqlib
--with-ms/libpq-dir
--without-ms/libpq-dir
--with-ms/libpq-include
--without-ms/libpq-include=${ms/libpq-dir}/include
--with-ms/libpq-lib
--without-ms/libpq-lib=${ms/libpq-dir}/lib
--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/tim/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-20/2.7.0/pg-1.2.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/tim/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/pg-1.2.3 for inspection.
Results logged to /Users/tim/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-20/2.7.0/pg-1.2.3/gem_make.out

--

I also tried to run with the following command:
gem install pg -- --with-pg-config=/opt/homebrew/opt/postgresql/bin/pg_config

What's wrong? Thanks

Tim

unread,
Jan 5, 2021, 10:46:22 AM1/5/21
to ruby-pg
I was able to install it by running the terminal with Rosetta 2 like so:
  Duplicate Terminal app
  Rename to "Terminal Rosetta"
  Right click > Get info > Check "Open using Rosetta"
  Run the following commands in this Terminal version

Then, I installed homebrew, postgresql@11, rbenv and ruby 2.7.1, and everything worked fine.

I also did the following:
  sudo rm -rf /Library/Developer/CommandLineTools
  xcode-select --install
  softwareupdate --install-rosetta

I hope this helps.
Thanks

Cody Cutrer

unread,
Jan 5, 2021, 1:52:46 PM1/5/21
to rub...@googlegroups.com
Using Rosetta is a bit of a copout when a developer is trying to natively develop on an M1 Mac. That said, I had no problem installing pg under arm64 doing this:

echo export PATH=$PATH:/opt/homebrew/bin >> ~/.zshrc
<restart shell>
brew install chruby
brew install ruby-install
ruby-install ruby 2.7.2
<restart shell>
chruby ruby-2.7.2
brew install postgresql@13
gem install pg

Note that I tried earlier before homebrew had bottles for arm64, and it had problems. So it may be recently fixed.

Cody Cutrer

--
You received this message because you are subscribed to the Google Groups "ruby-pg" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-pg+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-pg/b65bea8a-fd51-4e84-b1a2-3d3650113318n%40googlegroups.com.

Sol Martínez

unread,
Jan 12, 2023, 2:04:43 PM1/12/23
to ruby-pg
Thanks a lot cody! After a lot of unsuccessful searches, this worked for me!

Michael Huey

unread,
Mar 24, 2023, 1:19:22 PM3/24/23
to ruby-pg
Obviously you solved.

But much easier for me was simply running: 
`bundle config build.pg --with-pg-config=/opt/homebrew/opt/libpq/bin/pg_config`
then: 
`brew services restart postgresql@13`

Reply all
Reply to author
Forward
0 new messages