【问题标题】:An error occurred while installing pg (0.17.1), and Bundler cannot continue安装 pg (0.17.1) 时出错,Bundler 无法继续
【发布时间】:2014-01-12 07:03:41
【问题描述】:

我刚刚安装了Rails 4.0.2,在创建新应用程序时,在捆绑阶段我得到:

Installing pg (0.17.1) 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/Dee/.rvm/rubies/ruby-2.0.0-p247/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.

我该如何解决这个问题?

【问题讨论】:

  • 您可能想要添加一个 osx 标签。该解决方案似乎可能与您的操作系统特别相关。
  • 您可能想访问 . stackoverflow.com/questions/3116015/… 。希望这些解决方案之一有所帮助

标签: ruby-on-rails macos postgresql ruby-on-rails-4


【解决方案1】:

我刚刚设置了一个新的 Macbook Pro,它是用 Catalina 预构建的。

什么对我有用:

  1. 从这里安装 Postgres:https://postgresapp.com/
  2. export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"添加到您的.zshenv,因为Z shell 现在是默认终端。

【讨论】:

    【解决方案2】:

    如果您是通过 Homebrew 安装的; gem install pg -- --with-pg-config=/usr/local/bin/pg_config。适用于 Ruby 2.4.6 和 pg 0.20.0。

    【讨论】:

      【解决方案3】:

      我在使用 Amazon 时遇到问题,无法使用 apt-get。 对于我的工作:

          sudo yum install postgresql-devel
      

      然后:

          bundle install
      

      再试一次:

          rails serve
      

      【讨论】:

        【解决方案4】:

        以前使用旧版本的有效答案

        我安装在 mac OSX Mavericks 下,安装了 www.postgresapp.com 的 postgres 应用程序(版本 9.2.2.0)。根本问题很简单,因为 postgres 是通过应用程序安装的,所以配置文件驻留在一个位置,在没有 postgressapp 的情况下安装它时,该位置不是默认位置。所以我们需要告诉 gem 在哪里可以找到这个文件:

        gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
        

        希望对你有帮助

        【讨论】:

        • 这是我的解决方案 (OSX)
        • 如果这对任何人都不起作用,9.3 的配置文件已移动 - 请参阅接受的答案。
        【解决方案5】:

        对我有用

        rvm list gemsets
        rvm use ruby-2.4.1
        bundle
        

        ]2

        【讨论】:

        • 你没有在这里安装pg gem
        【解决方案6】:

        CentOS 用户:

        sudo yum install postgresql-devel
        

        gem install pg
        

        【讨论】:

          【解决方案7】:

          我在运行 Mavericks 的 Mac 上。我的解决方案是安装Postgres

          然后在终端中使用带有配置的自制软件安装:

          gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
          

          注意:此答案已被编辑为使用 Postgres 应用的发布版本中当前包含的 latest 符号链接。

          建议的以前版本:

          gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
          

          【讨论】:

          • 是的,我的也在不同的位置。感谢您的回答。
          • 正确的 Bob,对我有用的 postgresapp 版本是 9.2.2.0 版,所以他们必须在 9.3 版本中更改了这个位置。
          • 现在,截至 2015 年 1 月 22 日,我们正在关注 9.4 版本,很高兴看到他们一直在更新 -- "gem install pg -- --with-pg -config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config"
          • 我很着急,错过了这个答案中“使用自制软件安装”的部分。在我做了brew update; brew install postgres 之后,这个答案对我有用
          • 在您的解决方案中,请添加版本,其他最新的 PG gem 将安装:gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
          【解决方案8】:

          我需要使用 sudo

          sudo gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
          

          【讨论】:

            【解决方案9】:

            如果您在开发中使用 Postgres 以外的其他工具,并且仅在生产中使用 Postgres,您可以像这样将 pg gem 添加到您的 gemfile...

            group :production do
              gem 'pg',             '0.17.1'
            end
            

            然后使用bundle install --without production

            【讨论】:

              【解决方案10】:

              我必须结合一切并使用

              sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
              

              【讨论】:

                【解决方案11】:

                我设法克服这个错误的方法是:

                • cd 到 app 文件夹,然后在本地设置 ruby​​ 版本。我正在使用 ruby​​ 2.1.2。

                rbenv 本地 2.1.2

                • 不只是运行 bundle install,而是在 vendor/bundle 中安装 gems

                bundle install --path vendor/bundle

                这是为我做的。

                【讨论】:

                  【解决方案12】:

                  安装 Postgres 后,我必须运行以下命令

                  env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
                  

                  此捆绑包安装后效果很好!

                  希望对你有帮助

                  【讨论】:

                    【解决方案13】:

                    应用根目录:

                    1. 酿造更新
                    2. brew 安装 postgres
                    3. gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
                    4. 捆绑安装
                    5. ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
                    6. launchctl 加载 ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
                    7. createuser -s -r postgres
                    8. rake db:create:all
                    9. rake db:迁移
                    10. 导轨 s

                    注意:如果需要,请替换步骤 3 中的版本号。

                    【讨论】:

                      【解决方案14】:

                      如果 gem install pg 失败,请尝试以下命令:

                      env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
                      

                      ...来自PostgreSQL.app Documentation

                      【讨论】:

                      • 由于官方app最近更名为“Postgres93.app”,所以命令应该是:env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
                      • 对我来说它与:env ARCHFLAGS="-arch x86_64" gem install pg
                      【解决方案15】:

                      这里报告了某种错误Installing PG gem on OS X - failure to build native extension

                      要在 Ubuntu 上安装依赖项,试试这个:

                      sudo apt-get install libpq-dev
                      

                      还有这个

                      gem install pg
                      

                      【讨论】:

                      • 我在mac上,我该怎么办?
                      • 遵循 railstutorial.org 上的教程。这就是你需要为 Mint 做的事情。谢谢。
                      • railstutorial.org -- 付费教程;还有其他想法吗?
                      • @Deekor 如果您使用 Homebrew,则可以运行 brew install postgresql,然后应该正确安装 pg gem。见these docs
                      【解决方案16】:

                      您似乎没有安装 PostgreSQL。 pg gem 需要一些来自 PostgreSQL 的头文件来编译原生扩展。

                      【讨论】:

                      • 你的 Ruby/Bundler 设置怎么样?您使用的是 Mac OS X 还是 Linux?如果您使用的是 Mac OS X,您是通过 homebrew 或 PostgreSQL.app 安装 PostgreSQL?
                      • 我在 Mac 上。我是通过应用安装的
                      • 我安装了 0.17.0。将它与 rails 4 一起使用有什么危害吗?
                      • 然后尝试运行bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config 并再次运行bundle。如果您将应用安装到~/Application 而不是/Application,请调整配置路径
                      猜你喜欢
                      • 2018-04-05
                      • 2020-05-07
                      • 2021-05-13
                      • 2017-01-23
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      相关资源
                      最近更新 更多