无法安装pg

时间:2019-10-18 20:19:14

标签: ruby rubygems bundle homebrew pg

我一直在尝试安装一个说使用

的api。
bundle install
rails s

但是当我捆绑时,会出现此错误:

An error occurred while installing pg (0.18.1), and Bundler cannot 
continue. Make sure that `gem install pg -v '0.18.1' --source 'https://rubygems.org/'`succeeds before bundling.

但是当我运行该gem install命令时,我得到了:

错误:安装pg时出错:     错误:无法构建gem本机扩展。

current directory: /Library/Ruby/Gems/2.3.0/gems/pg-0.18.1/ext /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20191018-63874-el2g8s.rb extconf.rb checking for pg_config... yes Using config values from /usr/local/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.

mkmf.log文件显示:

ld: warning: directory not found for option '-L/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk/usr/local/libressl/lib'

我不太确定从哪里开始,因为我在网上一直遵循大量其他指南,但是它们要么无效,要么导致我遇到新的错误。

1 个答案:

答案 0 :(得分:0)

Install brew。这将处理所有依赖项,例如Xcode的命令行工具。在终端中运行以下命令以安装brew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew成功安装后,请使用以下命令安装PostgreSQL:

brew install postgresql

然后重试:

gem install pg -v '0.18.1' --source 'https://rubygems.org/'

请注意,指定的gem版本已经过期了将近五年。