无法安装pg gem(Rails 3 - Cygwin) - sh ::命令未找到

时间:2013-06-14 21:31:24

标签: ruby-on-rails-3 postgresql cygwin sh

当我跑步时

$ gem install pg

我得到以下

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby.exe 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
        --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=/usr/bin/ruby
        --with-pg
        --without-pg
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib
        --with-pg-config
        --without-pg-config
        --with-pg_config
        --without-pg_config


Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/pg-0.15.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/pg-0.15.1/ext/gem_make.out

当我跑步时

$ gem install pg -- --with-pg-config= /cygdrive/c/Program Files/PostgreSQL/9.0/bin/pg-config

我得到以下

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby.exe extconf.rb --with-pg-config= /cygdrive/c/Program Files/PostgreSQL/9.0/bin/pg-config
Using config values from
sh: : command not found
sh: : command not found
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
        --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=/usr/bin/ruby
        --with-pg
        --without-pg
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib
        --with-pg-config


Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/pg-0.15.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/pg-0.15.1/ext/gem_make.out

sh ::命令未找到”是什么意思?

这就是安装失败的原因吗?

背景:

  • 我正在使用Cygwin
  • 我使用了PostgreSQL的单击安装程序
  • pg_config.exe文件位于C / Program Files / PostgreSQL / 9.0 / bin / pg-config.exe
  • libpq-fe.h文件位于C / Program Files / PostgreSQL / 9.0 / include / libpq-fe.h

2 个答案:

答案 0 :(得分:2)

您不能混合使用本机Windows代码和Cygwin代码。如果您要链接到libpq,则需要 cygwin 版本libpq,并且您需要确保在pg_config上找到PATH的版本{1}}是cygwin。来自本机Windows构建的pg_config将产生Cygwin工具无法理解的输出,即使它们可能无法成功链接到本机库并与之一起运行。

由于我不再使用Cygwin,因此无法就当前安装libpq的方式提供任何建议。据推测,Cygwin的软件包管理中存在一个名为postgresql-clientlibpq等的库。

此时,Cygwin是PostgreSQL的一个非常低优先级的平台。鉴于Ruby + Rails和PostgreSQL都有本机Windows版本,你在这里设置困难,我建议你使用这两种工具的原生版本。你仍然可以使用msys bash在类似unix的shell环境中工作,并且如果不能选择MSVC ++,可以使用MinGW的gcc生成本机Windows可执行文件和库。

答案 1 :(得分:0)

这对我有用:

sudo apt-get install postgresql
sudo apt-get install libpq-dev

然后

gem install pg