![](/img/trans.png)
[英]MacOs (M1 Arm64) unable to load Nokogiri - Using system default Ruby
[英]ARM64 architecture (M1 chip): Cannot install pg gem (using PostgresApp)
我一直在嘗試在運行 Big Sur 的計算機(帶有 M1 的 Macbook Pro 2020)上安裝 rails 項目。
我安裝了 PostgresApp。
運行bundle install
時,無法構建pg
gem,所以我嘗試手動安裝 gem(通過執行gem install pg
- 也嘗試使用gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/10/bin/pg_config
)。
我收到一條錯誤消息:
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
檢查錯誤日志時,我看到:
have_library: checking for PQconnectdb() in -lpq... -------------------- no
ld: warning: ignoring file /Applications/Postgres.app/Contents/Versions/13/lib/libpq.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
"_PQconnectdb", referenced from:
_t in conftest-db479f.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
4:
5: /*top*/
6: extern int t(void);
7: int main(int argc, char **argv)
8: {
9: if (argc > 1000000) {
10: printf("%p", &t);
11: }
12:
13: return 0;
14: }
15: int t(void) { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return !p; }
/* end */
知道如何解決這個問題嗎?
我在 M1 + ruby pg gem 上遇到了同樣的問題。 問題是我的系統上混合了 ARM + x86 二進制文件,而pg
目前顯然只能用 x86 編譯。 僅供參考,在其 github 存儲庫中報告了新問題,因此希望它會很快在這里得到解決
我的工作:
卸載基於 ARM 的自制軟件 + rbenv 並從主目錄中刪除.gem
+ .rbenv
目錄(自制軟件卸載說明)
重新安裝自制軟件為 x86 intel-based
$ arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
$ arch -x86_64 brew install rbenv
$ arch -x86_64 rbenv install 2.7.2
$ bundle config build.pg- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
$ bundle install
$ rails s
我在 macOS M1(12 Monterey)上使用 Ruby 2.7 成功安裝了 pg gem,我同時安裝了 x86 和 arm64 brew。 由於pg必須用x86 libpq編譯,所以我用x86 brew安裝了libpq
❯ which brow
brow: aliased to arch --x86_64 /usr/local/Homebrew/bin/brew
❯ brow install libpq
❯ brew install PostgreSQL # Install arm64 PostgreSQL
❯ brew services start postgresql
❯ ps -ef | grep postgresql
501 23655 1 0 2:29PM ?? 0:00.10 /opt/homebrew/opt/postgresql/bin/postgres -D /opt/homebrew/var/postgres
❯ which brew
/opt/homebrew/bin/brew
❯ brew -v
Homebrew 3.3.2-50-geca16a2
Homebrew/homebrew-core (git revision ec99d74792c; last commit 2021-11-05)
Homebrew/homebrew-cask (git revision 2ab51af9c3; last commit 2021-11-05)
然后我可以安裝 pg gem
❯ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
❯ gem install pg -v 1.2.3 -- --with-pq-dir=/usr/local/Cellar/libpq/13.3
Building native extensions with: '--with-pq-dir=/usr/local/Cellar/libpq/13.3'
This could take a while...
Successfully installed pg-1.2.3
Parsing documentation for pg-1.2.3
Done installing documentation for pg after 0 seconds
但是 Ruby 2.6 失敗了,我不知道為什么
gem install pg -v 1.2.3 -- --with-pq-dir=/usr/local/Cellar/libpq/13.3
Building native extensions with: '--with-pq-dir=/usr/local/Cellar/libpq/13.3'
This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /Users/felix/.rvm/gems/ruby-2.6.6/gems/pg-1.2.3/ext
/Users/felix/.rvm/rubies/ruby-2.6.6/bin/ruby -I /Users/felix/.rvm/rubies/ruby-2.6.6/lib/ruby/site_ruby/2.6.0 -r ./siteconf20211105-41969-1oxcuyy.rb extconf.rb --with-pq-dir\=/usr/local/Cellar/libpq/13.3
checking for pg_config... yes
Using config values from /opt/homebrew/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)
對於那些只是嘗試安裝 pg gem 並且不關心 PostgresApp 的人,在 M1 上修復 pg 的關鍵是確保libpq
的存在。 這些步驟允許我在我的 M1 mac 上安裝 pg gem,而無需使用 x86 版本或構建標志:
brew install libpq
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
gem install pg
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.