简体   繁体   中英

Why am I getting this error when attempting to use postgresql as database in RoR?

I am working on starting a new project and I am getting an error I can't resolve after following the error's suggestions. Anybody out there know of any reason why Ruby 2.1.2 should not play well with Rails 4.2.6 when installing postgresql database? I am getting this type of error:

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.

I checked the logs and it might as well have been in hieroglyphics:

"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 */

I since changed to Ruby version 2.1.2, hoping it was a compatibility issue, but it did not resolve the error. When I try to follow the suggestions of error:

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

I get what you see above.

丹尼尔(Daniel)在评论中对此进行了详细说明,我对此不承担任何责任,但是如果您是Mac用户,则需要使用:

brew install postgresql

This error means you don't have the headers to compile the native extensions in your machine. You may install them by doing:

 brew install postgresql

ot then

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

and then try to run bundle install again.

You may read more about this here .

Try this: Go to System Settings => Open Software & Updates , you need to have both trusty-security & trusty-updates are enabled under the Updates tab, then reload your sources & see if you get the current versions. After that open your terminal and run sudo apt-get update .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM