0

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.
Mahir
  • 1,684
  • 5
  • 31
  • 59

2 Answers2

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

Community
  • 1
  • 1
SreekanthGS
  • 988
  • 5
  • 12
  • I think it fixed the issue... but I still have to check. Is it okay if I manually installed postgres from the website before I did it via HomeBrew? – Mahir Apr 22 '14 at 05:06
  • I'm not sure if this is still installation related, but the heroku instructions say to modify file `app/views/welcome/index.html.erb`, but the `app/views/welcome` folder is empty. (There is a welcome_controller.rb file in a separate path, but I'm not sure if this is the same thing) – Mahir Apr 22 '14 at 05:45
  • The article says to create a new file and add lines. `Next we’ll add an index page. In file app/views/welcome/index.html.erb write:...` – SreekanthGS Apr 22 '14 at 05:51
  • Are you saying I have to manually create a .erb file? I thought it should already be there – Mahir Apr 22 '14 at 06:00
  • You have to manually create erb files for views against actions. If you had done `rails generate controller welcome index`, it would have been there. But I suppose you did `rails generate controller welcome` which means you need to create views manually for actions like index which you define later. – SreekanthGS Apr 22 '14 at 06:02
  • I haven't done anything in 2 weeks, and I'm trying rails generate controller and it doesn't work anymore – Mahir May 05 '14 at 06:26
  • I posted the new error message above. I also tried all your tips and it still has problems with pg – Mahir May 05 '14 at 06:27
0

try

yum install postgresql-devel

or

brew install postgresql

then gem install pg should work

aelor
  • 10,892
  • 3
  • 32
  • 48