【问题标题】:Impossible to Install PG gem on my mac with Mavericks无法使用 Mavericks 在我的 Mac 上安装 PG gem
【发布时间】:2013-11-06 16:13:12
【问题描述】:

我正在尝试安装 pg gem,以便再次使用我的 rails 项目。但我得到这个错误:

构建原生扩展。这可能需要一段时间... 错误:错误 安装 pg: 错误: 无法构建 gem 原生扩展。

/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If

构建失败,请重试 --with-pg-config=/path/to/pg_config 检查 libpq-fe.h... 否 找不到 'libpq-fe.h 标头 * extconf.rb failed * 由于某种原因无法创建 Makefile,可能缺少必要的库和/或头文件。查看 mkmf.log 文件以获取更多详细信息。您可能需要配置 选项。

提供的配置选项:--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=/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby --with-pg --without-pg --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}/

Gem 文件将继续安装在 /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0 供检查。结果记录到 /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out

我尝试了在 stackoverflow 上找到的所有内容,但仍然出现此错误。

如果我尝试使用 brew 安装 postgresql,我会收到以下警告:

警告:postgresql-9.2.4 已经安装,只是没有链接

如果我尝试链接

brew 链接 postgresql 链接 /usr/local/Cellar/postgresql/9.2.4... 警告:无法链接 postgresql。取消链接...

错误:无法符号链接文件: /usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7 /usr/local/share/man/man7 不可写。你应该改变它 权限。

请帮忙

注意:我已经为 Mavericks 安装了命令行工具。


如果我使用自制软件卸载并尝试再次安装,我会收到此错误:

==> 正在下载http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2

################################################# ################ 100.0%

==> 打补丁 打补丁文件 src/pl/plpython/Makefile打补丁文件 contrib/uuid-ossp/uuid-ossp.c ==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local /地窖/p ==> 制作安装世界 ==>注意事项

构建说明

如果 PostgreSQL 9 的构建失败并且您使用的是 8.x 版 安装,您可能需要先删除以前的版本。见:
https://github.com/mxcl/homebrew/issues/issue/2510

创建/升级数据库

如果这是您的第一次安装,请使用以下命令创建数据库:initdb /usr/local/var/postgres -E utf8

从以前的主要版本(9.2 之前)迁移现有数据 PostgreSQL,见:
http://www.postgresql.org/docs/9.2/static/upgrading.html

加载扩展

默认情况下,Homebrew 构建所有可用的 Contrib 扩展。看到一个 所有可用扩展的列表,从 psql 命令行运行:
选择 * FROM pg_available_extensions;

要加载任何扩展名,请导航到所需的数据库 并运行:CREATE EXTENSION [扩展名];

例如,要在当前数据库中加载 tablefunc 扩展, 运行:创建扩展表函数;

有关 CREATE EXTENSION 命令的更多信息,请参阅:
http://www.postgresql.org/docs/9.2/static/sql-createextension.html For 有关扩展的更多信息,请参阅:
http://www.postgresql.org/docs/9.2/static/contrib.html

其他

某些机器可能需要配置共享内存:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC 安装 postgres gem 时,建议使用 ARCHFLAGS: ARCHFLAGS="-arch x86_64" gem install pg

要在不使用 sudo 的情况下安装 gem,请参阅 Homebrew wiki。

在登录时启动 postgresql: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents 然后现在加载 postgresql: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 或者,如果你不这样做 想要/需要launchctl,你可以运行: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start 警告:无法链接 PostgreSQL。取消链接... 错误:brew link 步骤未完成 成功建立了公式,但没有符号链接到 /usr/local 您可以使用 `brew link postgresql' 再试一次 ==> 总结 ???? /usr/local/Cellar/postgresql/9.2.4:2831个文件,38M,4.9分钟构建


解决方案:

我执行这个命令是为了改变文件夹的权限:

sudo chown jeanosorio /usr/local/share/man/man7

然后

brew 链接 postgresql 链接 /usr/local/Cellar/postgresql/9.3.1... 421 创建的符号链接

最后:

sudo ARCHFLAGS="-arch x86_64" gem install pg

获取:pg-0.17.0.gem (100%) 构建原生扩展。这可以 稍等一下……成功安装pg-0.17.0

【问题讨论】:

    标签: ruby-on-rails postgresql gem osx-mavericks


    【解决方案1】:

    我在 mac 上使用 homebrew 安装了 postgres。使用以下命令查找位置

    which postgres
    /usr/local/opt/postgresql@12/bin/postgres
    

    使用以下命令安装 gem。在上面的路径中,只需将 postgres 替换为 pg_config,因为命令需要 pg_config 的路径。

    gem install pg -- --with-pg-config=/usr/local/opt/postgresql@12/bin/pg_config
    

    【讨论】:

      【解决方案2】:

      对我来说,在 Yosemite 上,我不需要指定 pg_config 路径。下面就搞定了。

      brew install postgresql
      sudo env ARCHFLAGS="-arch x86_64" gem install pg
      

      似乎架构标志是关键。

      【讨论】:

        【解决方案3】:

        解决此问题的最简单方法是使用 Postgres.app 并设置我的环境变量,以便 gem install pg 正常工作(而不需要 --with-pg-config 标志)。

        使用Homebrew Cask

        brew cask install postgres
        echo 'export PG_HOME=/Applications/Postgres.app/Contents/Versions/latest' >> ~/.bash_profile
        echo 'export PATH="$PATH:$PG_HOME/bin"' >> ~/.bash_profile
        source ~/.bash_profile
        
        # now it just works
        gem install pg
        

        【讨论】:

          【解决方案4】:

          首先找到pg_config位置

          sudo find / -name "pg_config" -print
          

          答案是我的配置中的 /Library/PostgreSQL/9.1/bin/pg_config (MAC Maverick)

          然后尝试安装类似下面的东西

          gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

          如果这不起作用,请尝试检查您安装 postgresql 的方式

          brew/mac 端口/设置

          那么你必须尝试相同的相关选项。

          谢谢。

          内存

          【讨论】:

            【解决方案5】:

            对于任何迷失的灵魂仍然有这个问题没有解决,并安装了brew rubypostgres。以下是确保的步骤:

            • 确保您的ruby 版本没有安装--universal 标志。
              • 这是最难弄清楚的事情,我有--universal,这是问题的最终根源。
            • 确保您已使用 initdbcreatedb 命令正确初始化 postgresql(在别处查找执行此操作的步骤)。
            • 确保已安装Xcode(可选)和command line tools;在终端上:
              • xcode-select --install
              • sudo xcodebuild -license(如果安装了 Xcode)或打开应用程序并接受许可协议。
              • 重启电脑
            • which rubywhich gemwhich postgres 应分别显示 /usr/local/bin/ruby/usr/local/bin/gem/usr/local/bin/postgres
            • 在终端运行:

              • gem install pg -- --with-pg-config=/usr/local/bin/pg_config
              • env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
            • 确保所有这些步骤都得到满足,我能够解决以下错误:

              • ruby.h 标头错误
              • developer tools installed first错误

            【讨论】:

              【解决方案6】:

              如果您想避免使用 MacPorts,可以下载Postgres App 并将其放入 Application 目录。

              然后,指定新下载的pg_config的位置:

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

              如果您遇到缺少标头的问题,请尝试指定应用程序的include 目录:

              gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/Versions/latest/include/'
              

              【讨论】:

              • 请注意,您仍然可以通过设置配置环境变量来使用 bundler:export CONFIGURE_ARGS="with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config"
              • 如果您使用的是 Postgres 9.3(截至今天最新),您可以这样做:gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
              • 必须使用 gem install pg -- --with-pg-config=/Applications//Postgres.app/Contents/Versions/9.3/bin/pg_config 来完成这项工作
              • 谢谢!我收到警告:无法链接 postgresql。取消链接...错误:无法符号链接文件:...不可写。您应该更改其权限。一切都是 brew 错误,在我 brew install/link postgresql 安装到:链接 /usr/local/Cellar/postgresql/9.3.4... 在我的情况下这是一个非常冲突的文件夹,下载 pg 和 gem install 使用它解决了问题谢谢!!!!!!
              • export CONFIGURE_ARGS=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
              【解决方案7】:

              对我来说,错误消息如下所示:

              Installing pg 0.18.4 with native extensions

              Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

              ...

              checking for pg_config... no

              No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config

              正如错误消息所示,它正在尝试执行命令/脚本“pg_config”。因此,只需将其添加到 Postgres 安装所在的路径即可。就我而言,我做到了:

              export PATH=/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH

              然后

              bundle

              就是这样。

              【讨论】:

                【解决方案8】:

                如果在这里尝试一切后仍然无法安装,请尝试打开 Xcode 并接受许可协议。

                【讨论】:

                  【解决方案9】:

                  在我的情况下,如果您不指定拱标志、OS X 10.10.3 和 postersApp 9.4,它就不起作用

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

                  【讨论】:

                    【解决方案10】:
                    sudo su 
                    

                    然后

                    ARCHFLAGS="-arch x86_64" gem install pg -v '0.18'
                    

                    工作于 10.10.2

                    【讨论】:

                      【解决方案11】:

                      Postgres 9.4:

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

                      【讨论】:

                      • 稍微解释一下会很好,以避免在其他 19 个答案的洪流中丢失。
                      【解决方案12】:

                      我的捆绑包安装卡住了 3 天。尝试了所有方法,例如添加 env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/ pg_config

                      我能够看到在这个命令之后安装了 pg gem,但它仍然没有从 bundle install 安装,这很痛苦,因为除了 gem 'pg' 之外我不知道在 Gemfile 中要写什么

                      最终对我有用的是发现我的 pg_config 位于 /Library/PostgreSQL/9.3/bin/pg_config 并且默认情况下 Gemfile 包安装在 /usr/ 中本地/bin/pg_config

                      我刚刚运行了以下命令,神奇的事情发生了。 捆绑配置 build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

                      【讨论】:

                        【解决方案13】:

                        sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config

                        【讨论】:

                        • 这也适用于我的捆绑安装,如下所示:ARCHFLAGS="-arch x86_64" bundle install
                        【解决方案14】:

                        如果您想直接使用 postgresql 安装程序,这是另一种选择。在更新到小牛队之后,您必须先跳过几个箍。这是我所做的:

                        先安装xcode命令行工具:

                        xcode-select --install
                        

                        下载并安装最新版本的 PostgreSQL (9.3.1),就我而言,我只是使用图形安装程序。这是下载页面的链接:

                        http://www.enterprisedb.com/products-services-training/pgdownload#osx
                        

                        只需选择它为您提供的所有默认值。在我的情况下,它将 postgres 安装到以下目录,如果您将其安装到不同的目录,请记住您选择的路径,因为您很快就会需要它。

                        /Library/PostgreSQL/9.3
                        

                        如果您现在尝试安装最新的 pg gem (0.17.0),您需要在命令行上传递几个选项。这是我用的:

                        ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
                        

                        如果您将 postgres 安装到其他位置,则需要修复 pg_config 文件的路径。

                        如果它在尝试安装 pg gem 时抱怨缺少“libpq.5.dylib”文件,您需要创建一个指向该文件实际位置的符号链接。 Postgres 正在您的 /usr/local/lib/ 目录中查找它,因此在其中创建一个符号链接并将其重定向到其实际位置。就我而言,我必须运行:

                        sudo ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib /usr/local/lib/libpq.5.dylib
                        

                        完成此操作后,再次尝试安装 gem,希望它对您的工作方式与对我一样。

                        【讨论】:

                          【解决方案15】:

                          在 10.9.3 上使用 Xcode 5.1.1 对我有用的是:

                          brew update
                          brew install postgresql 
                          gem install pg -v '0.17.1'
                          

                          我需要 pg 0.17.1

                          【讨论】:

                            【解决方案16】:

                            在具有最新 Postgres 应用程序的 OS X Mavericks 上,使用 sudo 权限执行以下操作

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

                            【讨论】:

                              【解决方案17】:

                              就我而言,我卸载了通过自制软件安装的版本并切换到 Postgres.app(在撰写本文时为 v9.3.4.2)。

                              它似乎只在添加环境架构标志并指定pg_config 的路径时才有效。您的里程可能会有所不同,因此this answer 可以帮助您了解pg_config 位置的变化。

                              这是对我有用的最后一个完整的命令:

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

                              【讨论】:

                                【解决方案18】:

                                同样,在安装 Mavericks 'bundle update' 后,在 pg gem 上抛出了一个错误,它只用于生产而不是本地。

                                我使用 Brew 管理我的包,并且已经安装了 postgresql,但我仍然收到“no pg_config”错误。

                                解决方法是先“brew uninstall postgresql”,然后“brew install postgresql”。之后我立即能够成功运行“捆绑更新”

                                【讨论】:

                                  【解决方案19】:

                                  我在运行关于 pg gem 的 bundle install 时遇到了同样的错误(使用 Mac OS X Mavericks)。经过数小时的研究,我找到了解决方案。我使用自制软件安装了 postgres

                                  brew install postgres
                                  

                                  安装之后,我使用 postgres 创建了一个新的 rails 应用程序。我跑了

                                  bundle install
                                  

                                  无济于事(与问题相同的错误)。我用过

                                  which psql
                                  

                                  为了弄清楚我的 postgres 安装在哪里,它返回了

                                  /usr/local/bin/psql
                                  

                                  在再次运行 bundle install 之前,我必须通过运行以下命令来更改 build.pg 的全局路径

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

                                  然后我再次运行捆绑安装,瞧!我使用了 brew 安装它的 postgres。

                                  【讨论】:

                                    【解决方案20】:

                                    我无法通过 MacPorts 安装 postgres。相反,我安装了Postgress.app。并称为

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

                                    注意:在较新的版本中(至少在 9.3 中),路径实际上是: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config

                                    【讨论】:

                                    • 这可行,但请注意有时 Postgres.app 安装为 Postgres.app 其中 NN 是版本号。
                                    【解决方案21】:

                                    使用brew获取postgresql

                                    brew install postgresql
                                    

                                    检查您在已安装的 brew 中是否有 pg_config。我在

                                    中找到了我的

                                    /usr/local/Cellar/postgresql/9.3.3/bin/pg_config

                                    检查方式:

                                    $ ls /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
                                    > /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
                                    

                                    完成后,使用

                                    安装 pg gem
                                    env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
                                    

                                    【讨论】:

                                    • 在尝试了许多不同的事情后为我工作。我只需要确保使用正确的版本号(在我的情况下为 9.3.5_1)!
                                    • 使用ls /usr/local/Cellar/postgresql/9.*/bin/pg_config查找真实路径并结合env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=$(ls /usr/local/Cellar/postgresql/9.*/bin/pg_config)
                                    • 关于这里发生的事情的更详细描述deveiate.org/code/pg/README-OS_X_rdoc.html
                                    【解决方案22】:

                                    我遇到了同样的问题,这是我找到的解决方案。

                                    如果你运行brew doctor,它会告诉你可能你安装了一些没有 brew 的东西,改变了某些文件夹的权限,因此,你需要将那个文件夹的权限改回给你。

                                    /usr/local/share/man里面,你可以做的如下:

                                    sudo chown [yourusername] man7

                                    然后:

                                    brew link postgres

                                    希望对你有帮助!

                                    【讨论】:

                                      【解决方案23】:

                                      这对我有用:

                                      gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
                                      

                                      【讨论】:

                                        【解决方案24】:

                                        如果您有自制软件,只需输入:

                                        $ brew install postgresql

                                        【讨论】:

                                        • 这对我有用 - 我已经安装了 PostgreSQL,但我想我必须再次安装它,以刷新标题(?)然后我可以做 gem install pg
                                        【解决方案25】:

                                        这对我有用! (Postgres 93,mac ox 10.9.1)1。下载@http://postgresapp.com/ 和比

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

                                        【讨论】:

                                          【解决方案26】:

                                          将缺少的--with-pg-config 放在 Bundler 的配置文件中:/Users/<your_user>/.bundle/config,让您的生活更轻松。

                                          ---
                                          BUNDLE_BUILD__PG: --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
                                          BUNDLE_BUILD__EXAMPLE_GEM: --other-configs
                                          BUNDLE_BUILD__OTHER_EXAMPLE_GEM: --other-configs
                                          

                                          然后再次运行bundle install

                                          【讨论】:

                                            【解决方案27】:

                                            就我而言(我在 Mavericks 上需要 PG 0.16.0),我通过 MacPorts 安装了 postgresql

                                            sudo port install postgresql90
                                            

                                            然后

                                            gem install pg -v '0.16.0' -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
                                            

                                            最新版本需要扣除 -v '0.16.0'

                                            gem install pg -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
                                            

                                            如果您安装了 Homebrew,请不要在您之前安装 MacPorts read about their coexistense

                                            【讨论】:

                                              猜你喜欢
                                              • 1970-01-01
                                              • 2013-12-12
                                              • 2014-08-27
                                              • 2012-01-22
                                              • 2016-03-27
                                              • 2020-02-28
                                              • 1970-01-01
                                              • 2013-02-20
                                              相关资源
                                              最近更新 更多