[英]Ruby on Rails, Error when installing pg(1.2.3) [macOS Ventura 13.0, M1]
First time asking a question in stackoverflow, and sorry if my english is bad, but hope someone can help me:第一次在 stackoverflow 提问,如果我的英语不好,请见谅,但希望有人能帮助我:
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:在 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
Edit 1: Tried brew install libpq
then bundle install
again, but failed with same error.编辑 1:尝试brew install libpq
然后bundle install
再次,但失败并出现同样的错误。
Edit 2: Tried gem install pg -v 1.2.3 -- --with-pg-config=/opt/homebrew/bin/pg_config
also failed with same error.编辑 2:尝试gem install pg -v 1.2.3 -- --with-pg-config=/opt/homebrew/bin/pg_config
也因同样的错误而失败。
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.编辑 3:尝试bundle config build.pg --with-pg-config=/opt/homebrew/opt/libpq/bin/pg_config
然后bundle install
也失败并出现同样的错误。
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.编辑 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
也失败了错误。
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.所以..已经好几天了,但我没有找到解决方案,可能是因为 Rails 版本太旧或与 Apple Silicon 芯片不兼容。
But I did a work-around(?) by setting up this project with docker so it can be runned locally on my mac.但是我通过使用 docker 设置这个项目做了一个解决方法(?),所以它可以在我的 mac 上本地运行。
Same problem.同样的问题。 Resolved by reinstalling xcode command-line tools:重新安装xcode命令行工具解决:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.