You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M1芯片Ventura系统下安装pg gem遇多类错误求助

M1 MacOS Ventura 下 pg(1.4.1) 安装失败的解决办法

1. 规避sudo导致的权限与架构问题

直接使用sudo gem install会破坏Ruby环境的用户隔离,同时容易触发x86_64架构兼容性问题,优先采用本地bundle路径解决权限问题:

  • 配置项目本地bundle依赖路径,避免系统级权限要求:
    bundle config set path 'vendor/bundle'
    
    后续bundle install会将依赖安装到项目目录下的vendor/bundle,无需sudo。

2. 指定PostgreSQL路径与arm64架构编译参数

M1芯片为arm64架构,pg gem默认可能找不到arm64版本的PostgreSQL库,需明确指定编译参数:

情况1:直接安装pg gem

执行以下命令(Homebrew安装的Postgres 14.7默认路径为/opt/homebrew/opt/postgresql@14,可根据实际路径调整):

gem install pg -v 1.4.1 -- --with-pg-config=/opt/homebrew/opt/postgresql@14/bin/pg_config --with-cflags="-arch arm64" --with-ldflags="-arch arm64"

情况2:通过bundle安装

先配置bundle编译参数,再执行安装:

bundle config build.pg --with-pg-config=/opt/homebrew/opt/postgresql@14/bin/pg_config --with-cflags="-arch arm64" --with-ldflags="-arch arm64"
bundle install

3. 验证环境架构一致性

  • 确认终端为原生arm64模式:打开终端时,右键终端应用选择「打开」,不要勾选「使用Rosetta打开」。
  • 检查PostgreSQL架构:执行file /opt/homebrew/opt/postgresql@14/bin/postgres,输出需包含Mach-O 64-bit executable arm64;若为x86_64,重新安装arm64版本:
    brew uninstall postgresql@14 && brew install postgresql@14
    
  • 确认gcc为arm64版本:执行gcc -v,输出的target字段应为arm64-apple-darwinxx(xx对应Ventura版本号);若不符,重新安装Homebrew版gcc:
    brew install gcc
    

内容的提问来源于stack exchange,提问作者David Kabeya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 08:22:17