【问题标题】:gem install pg --with-pg-config works, bundle failsgem install pg --with-pg-config 有效,捆绑失败
【发布时间】:2012-03-03 08:18:24
【问题描述】:

当我运行时(以 root 身份)

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

我得到以下输出:

#-> gem instal pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config
Building native extensions.  This could take a while...
Successfully installed pg-0.12.0
1 gem installed
Installing ri documentation for pg-0.12.0...
Installing RDoc documentation for pg-0.12.0...
#-> 

当我运行捆绑安装时:

Installing pg (0.12.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-1.9.2-p290/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.

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=/usr/local/rvm/rubies/ruby-1.9.2-p290/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 /var/www/simpletrac/vendor/cache/ruby/1.9.1/gems/pg-    0.12.0 for inspection.
Results logged to /var/www/simpletrac/vendor/cache/ruby/1.9.1/gems/pg-0.12.0/ext/gem_make.out
An error occured while installing pg (0.12.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.0'` succeeds before bundling.

我在 /usr/pgsql-9.1/include/libpq-fe.h 中安装了 libpq-fe.h。所以,我尝试了

gem install pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config --with-pg-lib=/usr/pgsql-9.1/include/libpq-fe.h but still no go. 

任何帮助将不胜感激。

另外,我已经安装了 postgresql91-devel 和 ruby​​-devel。运行 CentOS 6。

【问题讨论】:

    标签: postgresql rubygems bundler pg


    【解决方案1】:

    我用的是mac,不想在本地安装postgresql。

    安装 libpq 并设置捆绑器配置对我有用。

    Reference link

    【讨论】:

      【解决方案2】:

      在 OSX 中,首先安装 pg:

      brew install postgresql
      

      其次,做 gem 安装:

      gem install pg --source 'https://rubygems.org/'
      

      然后你可以运行bundle install

      【讨论】:

        【解决方案3】:

        一些关于 UBUNTU 的案例

        sudo apt-get install libpq-dev
        

        在 CentOS 7 上

        sudo yum install postgresql-devel
        

        然后

        bundle install
        

        这对我有用。

        【讨论】:

          【解决方案4】:

          确保您已安装 postgress。如果不先安装它。以终端为例。

          brew install postgresql
          

          之后运行

          bundle install
          

          【讨论】:

            【解决方案5】:

            复制粘贴:

            bundle config build.pg --with-pg-config=`which pg_config` && bundle
            

            详情:

            访问以获取更多信息:

            您应该做的第一件事是确保 Postgres 附带的“pg_config”工具在您的路径中。如果不是,或者您路径中的第一个不是您要构建的 Postgres 安装的那个,您可以使用 --with-pg-config 选项指定它的路径。 em>

            来源: https://github.com/ged/ruby-pg/blob/1f274f68c16f1af1c642db1b9d3d28aef169dc84/ext/extconf.rb#L27

            【讨论】:

              【解决方案6】:

              这个link 建议使用:

              gem install pg --pre
              

              我几天都无法安装pg gem,但这种方法终于对我有用。希望这会有所帮助。

              【讨论】:

                【解决方案7】:

                你什么时候在 Mac 上使用 postgresapp,阅读http://postgresapp.com/documentation/cli-tools.html 文档并配置你的 $PATH。在此之前尝试再次运行捆绑安装。

                【讨论】:

                  【解决方案8】:

                  如果您不确定您的 pg_config 在哪里,并且假设您在 Linux 或 Mac 上,您可以运行以下命令:

                  which pg_config
                  

                  这将返回 ==> /usr/pgsql-9.1/bin/pg_config

                  现在使用这个路径

                  bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config
                  

                  现在完成bundle install

                  【讨论】:

                    【解决方案9】:

                    我正在使用 Arch Linux,并且遇到了类似的问题。使用sudo pacman -S libpqxx 并重新运行,然后安装pg gem,然后再次运行bundle install,这次终于成功了!

                    【讨论】:

                    • 我也在使用 Arch Linux,这解决了我的问题!
                    • 2016,postgresql 9.5 和 pg 0.18.4 似乎不适用于上述解决方案(我也在使用 arch linux)。
                    【解决方案10】:
                    gem install pg -v '0.17.1'
                    

                    为我做了诀窍。

                    【讨论】:

                      【解决方案11】:

                      我在 Mac 上使用 Homebrew,所以为了解决这个问题,我刚刚使用 brew 安装了 postgresql:

                      brew install postgresql
                      

                      然后安装 gem。

                      【讨论】:

                        【解决方案12】:

                        在运行 bundle install 之前,您是否尝试过运行它?

                        bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config
                        

                        http://bundler.io/v1.3/bundle_config.html

                        【讨论】:

                        • 如果您使用的是 MacOS + MacPorts,请参阅 Lester 的帖子了解解决方案。
                        • 我有同样的错误,但我使用的是 mysql 数据库。请问命令是什么??
                        • 这似乎有MySql的答案:stackoverflow.com/a/9360181/171933
                        • 在 CentOS 6 上的工作就像一个魅力!只需要在整个安装完全成功之前运行yum install postgresql-devel
                        • 另外--with-pg-dir=/usr/pgsql-<version> 处理配置和库。
                        【解决方案13】:

                        Postgres gem 找不到 Postgres 配置文件。你需要告诉它它在哪里。在我看来,最令人愉快的解决方案是跳过 Brew 和 MacPorts,只使用 Postgres 应用程序。从这里下载并安装:

                        http://postgresapp.com/

                        现在将 bin 文件夹添加到您的路径:

                        PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
                        

                        您可能还希望将其添加到您的 ~/.bash_profile

                        现在安装 gem:

                        gem install pg
                        

                        应该会很顺利。

                        【讨论】:

                          【解决方案14】:

                          试试这个:

                          yum install libpqxx-devel
                          

                          它适用于 Postgr9.2。

                          【讨论】:

                            【解决方案15】:

                            我必须这样做才能在 OS X 上修复我的问题:

                            export PATH=/opt/local/lib/postgresql84/bin/:$PATH
                            

                            尽管我已经在我的道路上遇到了这个事实,但我不得不这样做:

                            [user@foo ~] which psql84
                            /opt/local/bin/psql84
                            
                            [user@foo ~] ls -altrh /opt/local/bin/psql84 
                            lrwxr-xr-x  1 root  admin    36B Dec  7 02:15 /opt/local/bin/psql84 ->  /opt/local/lib/postgresql84/bin/psql
                            

                            我希望能帮助其他 Mac 用户解决这个问题。

                            【讨论】:

                            • 谢谢我已经在 Mac Yosemite 上测试了这个解决方案。
                            【解决方案16】:

                            遇到同样的问题,通过安装 libpq-dev 解决。

                            参考:https://bitbucket.org/ged/ruby-pg/issue/83/help-gem-install-pg-failed-on-opensuse-103

                            【讨论】:

                              【解决方案17】:

                              如果您安装了 pg_config 但它不在任何路径中,您可能会收到此错误。您可以将它添加到 ~/.bashrc 中的 PATH 环境中。

                              例如。

                              export PATH=${PATH}:/usr/pgsql-9.2/bin
                              

                              【讨论】:

                              • 这可能是从源代码而不是包管理器安装的结果吗?无论如何都为我工作 - 只是好奇我为什么遇到这个问题。
                              【解决方案18】:

                              如果有人使用 macports 安装 postgres 并且在找到他们的 pg_config 时遇到问题,试试这个:

                              bundle config build.pg --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config
                              

                              我希望这可以帮助某人节省一些时间。干杯!

                              【讨论】:

                                猜你喜欢
                                • 2014-09-14
                                • 2021-07-11
                                • 1970-01-01
                                • 2015-04-23
                                • 2014-01-09
                                • 1970-01-01
                                • 2017-08-27
                                • 1970-01-01
                                • 1970-01-01
                                相关资源
                                最近更新 更多