gem安装pg for ruby​​ on rails

时间:2016-09-02 22:30:19

标签: ruby-on-rails ruby

Postgresql不会在OSX上安装 这是我的数据

安装pg(0.18.4)时发生

n错误,并且Bundler无法继续。     在捆绑之前确保gem install pg -v '0.18.4'成功。     chriss-MacBook-Pro:shine chriswilson $ bundle exec install     用法:安装[-bCcpSsv] [-B后缀] [-f flags] [-g group] [-m mode]                    [-o owner] file1 file2            安装[-bCcpSsv] [-B后缀] [-f flags] [-g group] [-m mode]                    [-o owner] file1 ... fileN目录            install -d [-v] [-g group] [-m mode] [-o owner]目录...     chriss-MacBook-Pro:闪耀chriswilson $ gem install pg -v' 0.18.4'     构建原生扩展。这可能需要一段时间......     错误:安装pg时出错:         错误:无法构建gem原生扩展。

    current directory: /Users/chriswilson/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/ext
/Users/chriswilson/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160902-1617-e1qwb1.rb 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.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/chriswilson/.rvm/rubies/ruby-2.3.0/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/chriswilson/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-15/2.3.0/pg-0.18.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/chriswilson/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4 for inspection.
Results logged to /Users/chriswilson/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-15/2.3.0/pg-0.18.4/gem_make.out
chriss-MacBook-Pro:shine chriswilson$ gem install pg -v '0.18.4'
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    current directory: /Users/chriswilson/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4/ext
/Users/chriswilson/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20160902-1643-jfhxyo.rb 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.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/chriswilson/.rvm/rubies/ruby-2.3.0/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/chriswilson/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-15/2.3.0/pg-0.18.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/chriswilson/.rvm/gems/ruby-2.3.0/gems/pg-0.18.4 for inspection.
Results logged to /Users/chriswilson/.rvm/gems/ruby-2.3.0/extensions/x86_64-darwin-15/2.3.0/pg-0.18.4/gem_make.out



find_executable: checking for pg_config... -------------------- no

--------------------

find_header: checking for libpq-fe.h... -------------------- no

"gcc -o conftest -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/x86_64-darwin15 -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/backward -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/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 -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  -L. -L/Users/chriswilson/.rvm/rubies/ruby-2.3.0/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib     -lruby.2.3.0  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"gcc -E -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/x86_64-darwin15 -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/include/ruby-2.3.0/ruby/backward -I/Users/chriswilson/.rvm/rubies/ruby-2.3.0/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 -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 */

--------------------

2 个答案:

答案 0 :(得分:16)

这基本上意味着您在设置中错过了一个库或程序。我现在已经有过几次这个问题,所以这里有几个不同的尝试(希望其中一个适合你):

安装常见的缺失库:

brew install libpqxx
gem install pg

重新安装postgres(我不知道):

brew uninstall postgresql
brew install postgresql
gem install pg

明确定义pg_config的路径:

1)获取pg_config的位置

which pg_config

2)将该路径传递给gem install

gem install pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config

答案 1 :(得分:0)

尝试一下,它将起作用

sudo apt-get install -y libpq-dev build-essential postgresql-server-dev-all libpgsql-ruby postgresql ruby-dev && gem install pg