简体   繁体   中英

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

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. Run Could not find gem 'spring (>= 0) ruby' in the gems available on this machine. Run bundle install to 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.

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

try

yum install postgresql-devel

or

brew install postgresql

then gem install pg should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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