为什么在尝试将postgresql用作RoR中的数据库时出现此错误?

时间:2017-02-02 21:52:43

标签: ruby-on-rails ruby postgresql

我正在开始一个新项目,我收到一个错误,我无法在解决错误的建议后解决。任何人都知道在安装postgresql数据库时Ruby 2.1.2不能与Rails 4.2.6一起运行的任何原因? 我收到了这种错误:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
 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.

我检查了日志,它也可能是象形文字:

"gcc -E -I/Users/danale/.rvm/rubies/ruby-2.3.3/include/ruby-2.3.0/x86_64-darwin16 -I/Users/danale/.rvm/rubies/ruby-2.3.3/include/ruby-2.3.0/ruby/backward -I/Users/danale/.rvm/rubies/ruby-2.3.3/include/ruby-2.3.0 -I.  -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens  -fno-common -pipe  conftest.c -o conftest.i"
conftest.c:3:10: fatal error: 'libpq-fe.h' file not found
#include <libpq-fe.h>
         ^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
/* end */

我改为Ruby版本2.1.2,希望它是一个兼容性问题,但它没有解决错误。当我尝试遵循错误的建议时:

Gem files will remain installed in /Users/danale/.rvm/gems/ruby-2.1.2/gems/pg-0.19.0 for inspection.
Results logged to /Users/danale/.rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-16/2.1.0/pg-0.19.0/gem_make.out
danales-MacBook-Pro:Projects danale$ bundle exec spring binstub --all
Could not locate Gemfile or .bundle/ directory
danales-MacBook-Pro:Projects danale$ bundle install
Could not locate Gemfile

我得到你上面看到的。

3 个答案:

答案 0 :(得分:3)

丹尼尔在评论中指出了这一点,我不需要归功于它,但如果您是Mac用户,则需要使用:

brew install postgresql

答案 1 :(得分:1)

此错误表示您没有标头来编译计算机中的本机扩展。您可以通过执行以下操作来安装它们:

 brew install postgresql

然后

gem install pg -- --with-pg-config='PG_CONFIG_PATH'

然后尝试再次运行bundle install

您可以阅读有关此here的更多信息。

答案 2 :(得分:0)

试试这个: 转到系统设置=&gt;打开软件&amp;更新,您需要同时拥有可信赖安全&amp;在更新标签下启用可信赖更新,然后重新加载您的来源&amp;看看你是否得到了当前的版本。 之后打开终端并运行sudo apt-get update