【问题标题】:Ruby on Rails, Error when installing pg(1.2.3) [macOS Ventura 13.0, M1]Ruby on Rails,安装 pg(1.2.3) 时出错 [macOS Ventura 13.0,M1]
【发布时间】:2022-12-31 19:07:54
【问题描述】:

第一次在 stackoverflow 提问,如果我的英语不好,请见谅,但希望有人能帮助我:

所以,一个项目正在使用:

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

编辑 1: 尝试了brew install libpq,然后又尝试了bundle install,但失败并出现同样的错误。

编辑 2: 试过 gem install pg -v 1.2.3 -- --with-pg-config=/opt/homebrew/bin/pg_config 也因同样的错误而失败。

编辑 3: 试过 bundle config build.pg --with-pg-config=/opt/homebrew/opt/libpq/bin/pg_config 然后 bundle install 也失败了同样的错误。

编辑 4: 试过 sudo env ARCHFLAGS="-arch x86_64" gem install pg -v 1.2.3 -- --with-pg-config=/opt/local/lib/postgresql@14/bin/pg_config 也失败了同样的错误。

【问题讨论】:

    标签: postgresql ruby-on-rails-5 apple-m1 pg macos-ventura


    【解决方案1】:

    所以..已经好几天了,但我没有找到解决方案,可能是因为 Rails 版本太旧或与 Apple Silicon 芯片不兼容。

    但是我通过使用 docker 设置这个项目做了一个解决方法(?),这样它就可以在我的 mac 上本地运行。

    【讨论】:

    • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写出好的答案的信息in the help center。
    【解决方案2】:

    同样的问题。通过重新安装 xcode 命令行工具解决。

    sudo rm -rf /Library/Developer/CommandLineTools
    
    xcode-select --install
    

    【讨论】:

      猜你喜欢
      • 2023-02-04
      • 2022-12-17
      • 1970-01-01
      • 2021-08-18
      • 2021-05-13
      • 1970-01-01
      • 1970-01-01
      • 2017-08-16
      • 2012-12-11
      相关资源
      最近更新 更多