macOS Ventura 13.0(M1)安装pg(1.2.3) gem报错求助
求助:bundle install 安装pg gem失败
这是我首次在Stack Overflow提问,若表达有误还请见谅,希望能得到帮助:
我的项目使用以下配置:
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'
我已通过rbenv切换到正确的Ruby版本,但执行bundle install时遇到如下错误:
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
我已尝试以下方法,但均未解决问题:
- 执行
brew install libpq后再次运行bundle install,仍报错; - 执行
gem install pg -v 1.2.3 -- --with-pg-config=/opt/homebrew/bin/pg_config,仍报错; - 执行
bundle config build.pg --with-pg-config=/opt/homebrew/opt/libpq/bin/pg_config后运行bundle install,仍报错; - 执行
sudo env ARCHFLAGS="-arch x86_64" gem install pg -v 1.2.3 -- --with-pg-config=/opt/local/lib/postgresql@14/bin/pg_config,仍报错。
内容的提问来源于stack exchange,提问作者Justinus J J
相关产品推荐
相关产品推荐

