简体   繁体   English

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

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

I just installed Rails 4.0.2 and 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?我该如何解决?

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

I'm on a Mac running Mavericks.我在运行 Mavericks 的 Mac 上。 My solution was to install Postgres .我的解决方案是安装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 latest symlink that is currently included in shipping versions of the Postgres app.注意:此答案已被编辑为使用当前包含在 Postgres 应用程序的发布版本中的latest符号链接。

Previous versions suggested:以前的版本建议:

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

app root:应用程序根:

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

NOTE: replace the version number in step 3 if needed.注意:如果需要,请替换步骤 3 中的版本号。

Previously working answer with older version以前使用旧版本的工作答案

I installed under mac OSX Mavericks, having the postgres app (Version 9.2.2.0 ) from www.postgresapp.com installed.我安装在 mac OSX Mavericks 下,安装了来自www.postgresapp.com的 postgres 应用程序(版本 9.2.2.0)。 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.潜在的问题很简单,因为 postgres 是通过应用程序安装的,所以配置文件驻留在一个位置,在没有 postgressapp 的情况下安装它时,该位置不是默认位置。 so we need to tell gem where to find this file by:所以我们需要告诉 gem 在哪里可以找到这个文件:

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

Hope it helps希望它有帮助

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 文档

Looks like you do not have PostgreSQL installed.看起来您没有安装 PostgreSQL。 The pg gem requires some headers from PostgreSQL to compile native extension. 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

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

For CentOS users: CentOS 用户:

sudo yum install postgresql-devel

and

gem install pg

I have just set up a new Macbook Pro which was prebuilt with Catalina.我刚刚设置了一个新的 Macbook Pro,它是用 Catalina 预构建的。

What worked for me:什么对我有用:

  1. Install the Postgres from here: https://postgresapp.com/从这里安装 Postgres: https : //postgresapp.com/
  2. Add export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH" to your .zshenv , since Z shell is now the default terminal.export PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"到您的.zshenv ,因为 Z shell 现在是默认终端。

After installing Postgres I had to run the following command安装 Postgres 后,我必须运行以下命令

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

After this bundle install works great!在此捆绑安装后效果很好!

Hope it helps希望它有帮助

The way I managed to get past that error was:我设法克服该错误的方法是:

  • cd to app folder and then set the ruby version locally. cd 到 app 文件夹,然后在本地设置 ruby​​ 版本。 I'm using ruby 2.1.2.我正在使用 ruby​​ 2.1.2。

rbenv local 2.1.2 rbenv 本地 2.1.2

  • instead of just running bundle install, install the gems in vendor/bundle而不是仅仅运行 bundle install,在 vendor/bundle 中安装 gems

bundle install --path vendor/bundle捆绑安装 --path 供应商/捆绑

This did it for me.这为我做到了。

我需要使用 sudo

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

I was having a problem with Amazon and couldn't use apt-get.我在使用 Amazon 时遇到问题,无法使用 apt-get。 For my worked:对于我的工作:

    sudo yum install postgresql-devel

then:然后:

    bundle install

and try again:然后再试一次:

    rails serve

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

On mac this command worked for me.在 mac 上,这个命令对我有用。

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

It works for me这个对我有用

rvm list gemsets
rvm use ruby-2.4.1
bundle

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

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

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