Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何安装PostgreSQL:错误:无法生成gem本机扩展_Ruby_Postgresql_Rubygems - Fatal编程技术网

Ruby 如何安装PostgreSQL:错误:无法生成gem本机扩展

Ruby 如何安装PostgreSQL:错误:无法生成gem本机扩展,ruby,postgresql,rubygems,Ruby,Postgresql,Rubygems,运行捆绑安装时,我遇到以下错误: An error occurred while installing pg (0.21.0), and Bundler cannot continue. Make sure that `gem install pg -v '0.21.0' --source 'https://rubygems.org/'` succeeds before bundling. 之后我试着跑步 gem install pg -v '0.21.0' --source 'https:/

运行
捆绑安装时,我遇到以下错误:

An error occurred while installing pg (0.21.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.21.0' --source 'https://rubygems.org/'` succeeds before bundling.
之后我试着跑步

gem install pg -v '0.21.0' --source 'https://rubygems.org/'
这给了我这个错误:

ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/pg-0.21.0/ext
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200518-48011-1noawh0.rb extconf.rb
它还建议查看
mkmf.log
文件,该文件具有:

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

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

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

"xcrun clang -o conftest -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib   -arch x86_64   -lruby.2.6   "
ld: warning: directory not found for option '-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib'
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"xcrun clang -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS  -arch x86_64  -c conftest.c"
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 */

--------------------
find_可执行文件:检查pg_配置…------------不
--------------------
find_头:检查libpq fe.h..-------不
“xcrun clang-o conftest-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/sdk/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/Ruby-2.6.0/universal-darwin19-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.Platforms/Platforms/Developer/SDKs/MacOSX10.15.sdk/Systems/Ruby.framework/Versions/2.6/usr/include/Ruby-2.6.0/Ruby/backward-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/sdk/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.Frameworks/Versions/2.6/usr/include/Ruby-2.6.0-I.-D\XOPEN\u\u\u源代码-D\u达尔文\u源代码-D\u达尔文\u无限制\u选择-D\u可重入-g-Os-pipe-DHAVE\gCC_ATOMIC_BUILTINS conftest.c-L-L-L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib-L-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib-arch x86_64-lruby.2.6“
ld:警告:未找到选项'-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib'的目录
检查的程序是:
/*开始*/
1:#包括“ruby.h”
2: 
3:int main(int argc,字符**argv)
4: {
5:返回0;
6: }
/*结束*/
“xcrun clang-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/Ruby-2.6.0/universal-darwin19-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.Platforms/Platforms/Developer/Developer/MacOSX.15.sdk/System/Librarywork/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/sdk/System/Library/Frameworks/ruby.framework/Versions/2.6/usr/include/ruby-2.6.0-I.-D\u XOPEN\u-SOURCE-D\u达尔文\u C\u源代码-D\u达尔文\u无限选择-D\u可重入-g-Os-pipe-DHAVE\u GCC\u原子ILTINS-arch x86_64-c conftest.c“
conftest.c:3:10:致命错误:“未找到libpq fe.h”文件
#包括
^~~~~~~~~~~~
生成1个错误。
检查的程序是:
/*开始*/
1:#包括“ruby.h”
2: 
3:#包括
/*结束*/
--------------------
我不确定如何修复这个错误。我想它一定是查错文件夹了,对吧?但不知道如何解决这个问题


我正在使用Postgres应用程序,并将其放在Mac上的“我的应用程序”文件夹中。

您缺少Postgres源代码,需要它来编译pg gem

  • 使用安装brew

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    
  • 使用安装PostgreSQL server

    brew install postgresql
    
  • 但看起来您正在使用macOS附带的内置Ruby版本。我建议安装一个Ruby管理器,如RVM:

  • 安装带有

    \curl -sSL https://get.rvm.io | bash -s stable
    
  • 重新启动shell

  • 使用安装Ruby

    rvm install 2.7
    

  • 然后使用
    bundle install重新安装gems

    您缺少Postgres源代码,需要它来编译pg gem

  • 使用安装brew

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    
  • 使用安装PostgreSQL server

    brew install postgresql
    
  • 但看起来您正在使用macOS附带的内置Ruby版本。我建议安装一个Ruby管理器,如RVM:

  • 安装带有

    \curl -sSL https://get.rvm.io | bash -s stable
    
  • 重新启动shell

  • 使用安装Ruby

    rvm install 2.7
    
  • 然后使用
    bundle install重新安装gems

    查看选项列表,因为有许多Ruby管理器,RVM只是其中之一,任何安装它的人都应该密切注意文档。在MacOS上编译PG驱动程序还需要安装Xcode及其命令行工具。请参阅选择列表,因为有许多Ruby管理器,RVM只是其中之一,任何安装它的人都应密切注意有关的文档。在MacOS上编译PG驱动程序还需要安装Xcode及其命令行工具。