4

我需要在应用程序ROR中的生产环境中安装postgresql,以便在与heroku一起使用后,但是当我尝试安装gem'pg'时会触发以下错误。我是个新手,所以我不知道做Gem :: Ext :: BuildError:错误:无法构建gem本机扩展。 postgresql和ROR

我使用的红宝石1.9.3p547(2014年5月14日修订45962)[i686的Linux的] 轨

的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/[email protected]_master/gems/pg-0.17.1 for inspection. 
Results logged to /home/fernando/.rvm/gems/[email protected]_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. 

回答

21

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

,当我与轨开始这个配置是有关libpq的依赖,在描述出现的问题我面对这种problems,所以,我认为答案是只要按照以下步骤

"An error occured while installing pg 

1.sudo apt-get install libpq-dev 
2.sudo gem install pg 
" 
+2

谢谢rderoldan1。它工作完美。新手很难面对这些问题 – 2014-12-03 19:32:22

+0

真棒!非常感谢! – SsouLlesS 2015-02-20 02:48:27

10

上述解决方案没有为工作我,但指示here做。下面我将总结:

  • 确保您已经安装了PostgreSQL
  • 查找与sudo find/-name "pg_config"
  • 复制路径
  • 运行gem install pg -- --with-pg-config=path/to/pg_config
  • 成功新pg_config路径!
0

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/[email protected]/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没有任何错误。

0

就我而言,我在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

希望得到这个帮助。

相关问题