在Rails中默认使用postgres

时间:2018-09-18 16:50:27

标签: ruby-on-rails ruby windows postgresql

我是红宝石和Rails开发的新手。我知道Rails默认使用sqlite3,所以我想尝试使用postgres作为默认值。我已经下载了postgres,jruby,ruby 2.5.1,rails 5.2.1。我已经用ruby dk.rb init / install安装了ruby devkit。尝试安装pg gem时,我无意中发现了以下输出:

Building native extensions.  This could take a while...
C:/jruby-9.1.17.0/lib/ruby/stdlib/rubygems/ext/ext_conf_builder.rb:58: warning: Tempfile#unlink or delete called on open file; ignoring
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.
    current directory: C:/jruby-9.1.17.0/lib/ruby/gems/shared/gems/pg-1.1.3/ext
C:/jruby-9.1.17.0/bin/jruby.exe -r ./siteconf20180918-6200-16mdyzt.rb extconf.rb
checking for pg_config... yes
Using config values from C:\postgres\bin/pg_config.exe
RuntimeError: The compiler failed to generate an executable file.
You have to install development tools first.

     try_do at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:456
  try_link0 at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:541
   try_link at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:556
     <main> at extconf.rb:40
*** 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
        --without-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=C:/jruby-9.1.17.0/bin/jruby
        --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:
  C:/jruby-9.1.17.0/lib/ruby/gems/shared/extensions/universal-java-1.8/2.3.0/pg-1.1.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/jruby-9.1.17.0/lib/ruby/gems/shared/gems/pg-1.1.3 for inspection.
Results logged to C:/jruby-9.1.17.0/lib/ruby/gems/shared/extensions/universal-java-1.8/2.3.0/pg-1.1.3/gem_make.out

mkmf.log包含:

find_executable: checking for pg_config... -------------------- yes

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

" -o conftest.exe -I/include/universal-java1.8 -IC:/jruby-9.1.17.0/lib/ruby/include/ruby/backward -IC:/jruby-9.1.17.0/lib/ruby/include -I. -IC:/postgres/include     -fno-omit-frame-pointer -fno-strict-aliasing  -fexceptions  conftest.c  -L. -LC:/jruby-9.1.17.0/lib -LC:/postgres/lib  -LC:/jruby-9.1.17.0/lib/native/x86_64-Windows   -m64 -march=native -mtune=native      "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <ruby.h>
4: int main(int argc, char **argv)
5: {
6:   return 0;
7: }
/* end */

1 个答案:

答案 0 :(得分:0)

您是否已在系统中安装了postgres软件包?您可以使用命令在Linux中安装

sudo apt-get install postgresql postgresql-contrib

如果您使用的是Debian系统

该错误明确表明您需要安装开发工具,因此您可能会错过安装某些依赖项的机会

您可以使用以下命令通过命令行实用程序进行安装

     @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://s3.amazonaws.com/pgcentral/install.ps1'))"
     cd bigsql
     pgc install pg10
     pgc start pg10

请按照此link在Windows中配置Postgress

要安装postgres客户端,请参考this stackoverflow链接,并尝试通过指定pgconfig文件的路径来安装pg gem,您可以参考此 例如link