繁体   English   中英

安装 pg (0.17.1) 时出错,Bundler 无法继续

[英]An error occurred while installing pg (0.17.1), and Bundler cannot continue

我刚刚安装了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.

我该如何解决?

此处报告了某种错误在 OS X 上安装 PG gem - 无法构建本机扩展

要在 Ubuntu 上安装依赖项,请尝试以下操作:

sudo apt-get install libpq-dev

而这

gem install pg

我在运行 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

应用程序根:

  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 load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  7. createuser -s -r postgres
  8. 耙 db:create:all
  9. 耙数据库:迁移
  10. 导轨

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

以前使用旧版本的工作答案

我安装在 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

希望它有帮助

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

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

...来自PostgreSQL.app 文档

看起来您没有安装 PostgreSQL。 pg gem 需要来自 PostgreSQL 的一些头文件来编译本机扩展。

我必须结合一切并使用

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

如果您在开发中使用 Postgres 以外的东西,而只在生产中使用 Postgres,您可以像这样将 pg gem 添加到您的 gemfile 中...

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

然后使用bundle install --without production

CentOS 用户:

sudo yum install postgresql-devel

gem install pg

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

什么对我有用:

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

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

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

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

希望它有帮助

我设法克服该错误的方法是:

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

rbenv 本地 2.1.2

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

捆绑安装 --path 供应商/捆绑

这为我做到了。

我需要使用 sudo

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

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

    sudo yum install postgresql-devel

然后:

    bundle install

然后再试一次:

    rails serve

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

在 mac 上,这个命令对我有用。

gem install pg -v '0.18.4' -- --with-cflags="-Wno-error=implicit-function-declaration"

这个对我有用

rvm list gemsets
rvm use ruby-2.4.1
bundle

错误[![用 rvm 解决,使用 ruby ] 2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM