繁体   English   中英

Gem :: Ext :: BuildError:错误:无法构建gem原生扩展。 postgresql和ROR

[英]Gem::Ext::BuildError: ERROR: Failed to build gem native extension. postgresql and ROR

我需要在应用程序ROR中的生产环境中安装postgresql,以便在使用heroku之后使用它,但是当我尝试安装gem'pg'时会触发以下错误。 我是新手,所以我不知道那样做

我正在使用ruby 1.9.3p547(2014-05-14修订版45962)[i686-linux] rails

Rails 3.2.19 Ubuntu 12.04

的Gemfile

来源' https://rubygems.org '

宝石'轨道','3.2.19'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'
gem 'hirb'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :production do
  gem 'pg'

end


# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

我运行捆绑包更新或捆绑安装时出现问题

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

    /home/fernando/.rvm/rubies/ruby-1.9.3-p547/bin/ruby -r ./siteconf20141203-14261-3uu564.rb 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.

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=/home/fernando/.rvm/rubies/ruby-1.9.3-p547/bin/ruby
    --with-pg
    --without-pg
    --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

extconf failed, exit code 1

Gem files will remain installed in /home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/gems/pg-0.17.1 for inspection.
Results logged to /home/fernando/.rvm/gems/ruby-1.9.3-p547@ticket_master/extensions/x86-linux/1.9.1/pg-0.17.1/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

您的问题在日志No pg_config... trying anyway.

这个配置与libpq依赖关系有关,当我开始使用rails时遇到了这种问题 ,所以,我认为答案只是按照以下步骤进行

在控制台中运行此命令。

sudo apt-get install libpq-dev 
sudo gem install pg

上述解决方案对我不起作用,但这里的说明没有。 我将总结如下:

  • 确保你已经安装了PostgreSQL
  • 使用sudo find / -name "pg_config"新的pg_config路径
  • 复制路径
  • 运行gem install pg -- --with-pg-config=path/to/pg_config
  • 成功!

根据rderoldan1的解决方案,我运行如下(使用Fedora 23):

dnf install libpq-dev 

但是我收到了这条消息:

No package libpq-dev available. Error: Unable to find a match.

最初,使用以下命令安装PostgreSQL:

dnf install postgresql-server postgresql-contrib

当我运行which pg_config我得到了这个:

/usr/bin/which: no pg_config in (/usr/local/heroku/bin:/usr/local/rvm/gems/ruby-2.2.4/bin:/usr/local/rvm/gems/ruby-2.2.4@global/bin:/usr/local/rvm/rubies/ruby-2.2.4/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/local/rvm/bin:/home/mayur/.local/bin:/home/mayur/bin)

所以我用这个命令再次安装了PostgreSQL:

dnf install postgresql-devel

现在,当我运行which pg_config我得到:

/usr/bin/pg_config

我可以运行bundle install而不会出现任何错误。

就我而言,我在OSX El Capitan 10.11.5上使用Postgres 9.5.2,Ruby 2.3.0和Rails 4.2.6。 所有这些都正确设置并正常工作,直到我尝试在本地计算机上部署生产环境。 尝试上面的解决方案,虽然它指向了正确的方向,但它们都不适合我。

所以我的问题主要是关于bundler而不是gem install。 为了做到这一点,首先应按照上面的说明再次正确安装宝石。 pg_config的路径可能因Postgres版本而异。

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

要捆绑它,您可能需要在捆绑安装之前正确配置它

$bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.5/bin/pg_config
You are replacing the current global value of build.pg, which is currently "--with-pg-config=/opt/local/lib/postgresql91/bin/pg_config"

现在您应该能够毫无问题地运行bundle install

希望这有帮助。

暂无
暂无

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

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