安装pg(0.21.0)时发生错误,Bundler无法继续

时间:2017-10-24 14:38:19

标签: ruby ubuntu bundle shopify

我正在尝试关注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'

我该怎么办?谢谢。

6 个答案:

答案 0 :(得分:7)

实际上这对我有用

sudo apt-get install libpq-dev ruby-dev

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

答案 1 :(得分:3)

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

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

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

答案 2 :(得分:1)

尝试安装postgres:

简单安装postgresql

答案 3 :(得分:0)

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

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

然后我可以解决问题:

rails new MyAppName --database=postgresql 

答案 4 :(得分:0)

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

sudo apt-get install ruby-dev

答案 5 :(得分:0)

我认为您没有安装postgres。

  Try: brew install postgres