MacOS Ventura下Postgres.app安装pg 1.4.6原生扩展失败求助
解决MacOS Ventura下bundle安装pg 1.4.6 gem失败的问题
以下是针对你遇到的问题的具体解决步骤:
方法1:临时指定pg_config路径执行bundle
直接在bundle命令前指定Postgres.app的pg_config完整路径,绕过系统默认的错误路径:
PG_CONFIG=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config bundle install
注:如果你的Postgres.app使用的是特定版本(比如14),替换路径中的latest为对应版本号即可,例如/Applications/Postgres.app/Contents/Versions/14/bin/pg_config
方法2:确保.zshrc配置生效且优先级正确
检查你的~/.zshrc文件,确认Postgres.app的路径配置放在最前面(避免被其他路径覆盖):
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH" export LIBRARY_PATH="/Applications/Postgres.app/Contents/Versions/latest/lib:$LIBRARY_PATH"
保存文件后执行source ~/.zshrc使配置生效,再在终端输入which pg_config,确认输出是Postgres.app对应的路径,而非/usr/pgsql-9.3/bin/pg_config。如果输出不符合预期,重启终端后再次验证。
方法3:给bundler设置全局pg构建配置
如果临时命令有效,可以把pg_config路径配置到bundler全局设置中,后续无需每次手动指定:
bundle config set build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
配置完成后直接执行bundle install即可。
方法4:清理旧缓存并重新安装
如果之前有旧的pg gem缓存或Gemfile.lock的遗留配置干扰,先清理再重新安装:
- 删除项目根目录下的
Gemfile.lock文件 - 执行
bundle clean --force清理本地gem缓存 - 用方法1的命令重新执行
bundle install
内容的提问来源于stack exchange,提问作者Nahomie nd
相关产品推荐
相关产品推荐

