Ruby-on-rails 安装 pg (0.17.1) 时出错,Bundler 无法继续
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20754081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
An error occurred while installing pg (0.17.1), and Bundler cannot continue
提问by Deekor
I just installed Rails 4.0.2and when creating a new app, in the bundle stage I get:
我刚刚安装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.
How do I fix this?
我该如何解决?
回答by Talgat Medetbekov
Some kind of error resported here Installing PG gem on OS X - failure to build native extension
此处报告了某种错误在 OS X 上安装 PG gem - 无法构建本机扩展
To install dependencies on Ubuntu try this:
要在 Ubuntu 上安装依赖项,请尝试以下操作:
sudo apt-get install libpq-dev
and this
和这个
gem install pg
回答by Bob O'Brien
I'm on a Mac running Mavericks. My solution was to install Postgres.
我在运行 Mavericks 的 Mac 上。我的解决方案是安装Postgres。
And then in terminal install using homebrew with the configuration:
然后在终端安装使用自制软件和配置:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
Note: This answer has been edited to use the latestsymlink that is currently included in shipping versions of the Postgres app.
注意:此答案已被编辑为使用latest当前包含在 Postgres 应用程序的发布版本中的符号链接。
Previous versions suggested:
以前的版本建议:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
回答by knice
app root:
应用程序根:
- brew update
- brew install postgres
- gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.4/bin/pg_config
- bundle install
- ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
- launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
- createuser -s -r postgres
- rake db:create:all
- rake db:migrate
- rails s
- 酿造更新
- brew 安装 postgres
- gem install pg --with-pg-config=/usr/local/Cellar/postgresql/ 9.3.4/bin/pg_config
- 捆绑安装
- ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
- launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
- createuser -s -r postgres
- 耙 db:create:all
- 耙数据库:迁移
- 导轨
NOTE: replace the version number in step 3 if needed.
注意:如果需要,请替换步骤 3 中的版本号。
回答by Robertibiris
Previously working answer with older version
以前使用旧版本的工作答案
I installed under mac OSX Mavericks, having the postgres app (Version 9.2.2.0 ) from www.postgresapp.cominstalled. The underlying problem was simpy that the since postgres was installed via the app, the configuration file resides on a location which is not the default one when installing it without postgressapp. so we need to tell gem where to find this file by:
我安装在 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
Hope it helps
希望能帮助到你
回答by Vince
If gem install pg fails, try the following command:
如果 gem install pg 失败,请尝试以下命令:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
... from the PostgreSQL.app Documentation
...来自PostgreSQL.app 文档
回答by tungd
Looks like you do not have PostgreSQL installed. The pggem requires some headers from PostgreSQL to compile native extension.
看起来您没有安装 PostgreSQL。该pg宝石需要从PostgreSQL的一些头编译原生扩展。
回答by Mark Wang
I had to combine everything and use
我必须结合一切并使用
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
回答by j8d
If you are using something other than Postgres in development and Postgres in production only, you can add the pg gem to your gemfile like so...
如果您在开发中使用 Postgres 以外的东西,而只在生产中使用 Postgres,您可以像这样将 pg gem 添加到您的 gemfile 中...
group :production do
gem 'pg', '0.17.1'
end
Then use bundle install --without production
然后使用 bundle install --without production
回答by webster
For CentOS users:
CentOS 用户:
sudo yum install postgresql-devel
and
和
gem install pg
回答by Henrik Holm
I have just set up a new Macbook Pro which was prebuilt with Catalina.
我刚刚设置了一个新的 Macbook Pro,它是用 Catalina 预构建的。
What worked for me:
什么对我有用:
- Install the Postgres from here: https://postgresapp.com/
- Add
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"to your.zshenv, since Z shell is now the default terminal.
- 从这里安装 Postgres:https: //postgresapp.com/
- 添加
export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"到您的.zshenv,因为 Z shell 现在是默认终端。

