Issue with the installation of gem 'pg' in Heroku - Rails

ε祈祈猫儿з 提交于 2019-12-25 16:44:21

问题


I'm trying to install ruby on rails on OSX for heroku, for which I used this tutorial. It seemed to install fine on the terminal, but after doing

$rails new myapp --database=postgresql
cd myapp

I did this

rails generate controller welcome

and got an error:

Could not find gem 'spring (>= 0) ruby' in the gems available on this machine. Runbundle installto install missing gems.

And after following the instructions, I got

'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.'

And then...

ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        ...
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.

A similar SO question said the problem was solved by updating XCode, but I don't think that's my problem. If it wasn't already apparent, I'm not very experienced with the terminal or ruby, so I'm not sure how I can approach this issue.

EDIT:

new error message

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

    /Users/mahireusufzai/.rbenv/versions/2.1.1/bin/ruby extconf.rb 
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
*** 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.

...

/Users/mahireusufzai/.rbenv/versions/2.1.1/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/mahireusufzai/.rbenv/versions/2.1.1/lib/ruby/2.1.0/mkmf.rb:541:in `try_link0'
    from /Users/mahireusufzai/.rbenv/versions/2.1.1/lib/ruby/2.1.0/mkmf.rb:556:in `try_link'
    from extconf.rb:39:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/mahireusufzai/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/pg-0.17.1 for inspection.

回答1:


You need to install the postgresql development libraries first. It's complaining libpq-fe.h is missing.

Try to solve as per the answer in the following post: Rails: Error installing pg gem




回答2:


try

yum install postgresql-devel

or

brew install postgresql

then gem install pg should work



来源:https://stackoverflow.com/questions/23210542/issue-with-the-installation-of-gem-pg-in-heroku-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!