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

Posted

技术标签:

【中文标题】安装 pg (0.21.0) 时出错,Bundler 无法继续【英文标题】:An error occurred while installing pg (0.21.0), and Bundler cannot continue 【发布时间】:2018-04-05 10:07:50 【问题描述】:

我正在尝试关注this tutorial about Shopify Apps。 首先我尝试:

捆绑安装

但它给了我这个错误

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

    current directory: /tmp/bundler20171024-12759-18v2l7apg-0.21.0/gems/pg-0.21.0/ext
/usr/bin/ruby2.3 -r ./siteconf20171024-12759-2yizk4.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for
building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for
building a client-side application.
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.

Provided configuration options:
    --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=/usr/bin/$(RUBY_BASE_NAME)2.3
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --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/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /tmp/bundler20171024-12759-18v2l7apg-0.21.0/extensions/x86_64-linux/2.3.0/pg-0.21.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /tmp/bundler20171024-12759-18v2l7apg-0.21.0/gems/pg-0.21.0 for
inspection.
Results logged to
/tmp/bundler20171024-12759-18v2l7apg-0.21.0/extensions/x86_64-linux/2.3.0/pg-0.21.0/gem_make.out

An error occurred while installing pg (0.21.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.21.0'` succeeds before bundling.

In Gemfile:
  pg

但如果我尝试:

gem install pg -v '0.21.0'

这也给了我错误:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/pg-0.21.0/ext
/usr/bin/ruby2.3 -r ./siteconf20171024-12993-1t8i3d6.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
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.

Provided configuration options:
    --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=/usr/bin/$(RUBY_BASE_NAME)2.3
    --with-pg
    --without-pg
    --enable-windows-cross
    --disable-windows-cross
    --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/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/pg-0.21.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/pg-0.21.0 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/pg-0.21.0/gem_make.out

我已经看过了

sudo apt-get install libpq-dev

应该可以,但是,是的……错误:

Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libpq-dev : Depends: libssl-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

我正在开发 Ubuntu 16.04 LTS。 (这是gemfile:)

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#repo_name/#repo_name" unless repo_name.include?("/")
  "https://github.com/#repo_name.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for javascript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'shopify_app', '~> 7.0.0'

我该怎么办?谢谢。

【问题讨论】:

【参考方案1】:

尝试安装 postgres:

brew 安装 postgresql

【讨论】:

【参考方案2】:

其实这对我有用

sudo apt-get install libpq-dev ruby-dev

这需要我安装两个包libpq-devruby-dev

【讨论】:

【参考方案3】:

我认为你没有安装 postgres。

  Try: brew install postgres

【讨论】:

当您的答案太短时,最好作为评论发送。【参考方案4】:

您可能忘记安装 ruby​​-dev 软件包。 它为我解决了问题。

sudo apt-get install ruby-dev

【讨论】:

【参考方案5】:

我刚刚在我的 Mac(Rails 5,High-Sierra)上运行“rails new”命令并打开了--database=postgresql 选项时遇到了这个问题。这是对先前答案中提到的事情的一种重申,但我认为这可能会有所帮助。问题是因为我已将 Postgres 作为应用程序安装在我的 Applications 文件夹中,并且当“rails new”命令运行时,它找不到安装 pg gem 所需的包含。我所要做的就是让系统知道它们在哪里。所以我在终端执行了这个:

export CONFIGURE_ARGS=“with-pg-include=Applications/Postgres.app/Contents/Versions/latest/include/“

然后我可以毫无问题地运行:

rails new MyAppName --database=postgresql 

【讨论】:

在我找到的所有问题和提示中,您的问题似乎与我的情况最相关。我收到错误“找不到'libpq-fe.h 标头”与一个特定的rails 应用程序,但不是另一个rails 应用程序。问题是:如果我已经安装了mysql,我是否必须使用Postgrsql?【参考方案6】:

我相信你的问题的原因在这里

libpq-dev : Depends: libssl-dev but it is not going to be installed

你应该安装libssl-dev来解决它,它与ruby/pg无关,但需要他们正确安装pg gem。

【讨论】:

"但是他们需要正确安装 pg gem" 为什么? 好的,但现在我得到 libpq-dev: command not found

以上是关于安装 pg (0.21.0) 时出错,Bundler 无法继续的主要内容,如果未能解决你的问题,请参考以下文章

在 osx 上安装 pg gem 时出错

Symfony 4 为奏鸣曲管理包安装 sensio/generator-bundle 时出错

运行 gem install pg -v '0.15.1' 时出错

运行 bundle install 时如何传递 gem 安装的参数?

在 Heroku 上执行 rake db:migrate 时出错

Github 操作工作流 PG::ConnectionBad:无法连接到服务器:运行 bundle exec rake 时没有这样的文件或目录