1

My current Gemfile has

ruby "2.7.2"
gem "rails", "~> 7.0.2", ">= 7.0.2.3"
gem 'pg', '~> 0.18.4'

Please tell me if the following errors can lead me to a solution to get postgresql working in my Rails app. I have also tried gem 'pg', "~> 1.1.4" without success.

Bundle install includes these errors:

    current directory: /Users/francoisvanderhoven/.rvm/gems/ruby-2.7.2/gems/pg-0.18.4/ext
      /Users/francoisvanderhoven/.rvm/rubies/ruby-2.7.2/bin/ruby -I 
      /Users/francoisvanderhoven/.rvm/rubies/ruby-2.7.2/lib/ruby/2.7.0 -r 
      ./siteconf20220416-59183-japbu5.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 ***

    please check the mkmf.log which can be found here:
      /Users/francoisvanderhoven/.rvm/gems/ruby-2.7.2/extensions/x86_64-darwin- 
      21/2.7.0/pg-0.18.4/mkmf.log

When I inspect this mkmf.log file with nano, I see:

find_executable: checking for pg_config... -------------------- no
find_header: checking for libpq-fe.h... -------------------- no

"gcc -o conftest -I/Users/francoisvanderhoven/.rvm/rubies/ruby-2.7.2/include/ruby-2.7.0/x86_64-darwin21 -I/Users/francoisvanderhoven/.rvm/rubies/ruby-2.7.2/include/ruby-2.7.0/ruby/backward -I$
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

"gcc -E -I/Users/francoisvanderhoven/.rvm/rubies/ruby-2.7.2/include/ruby-2.7.0/x86_64-darwin21 -I/Users/francoisvanderhoven/.rvm/rubies/ruby-2.7.2/include/ruby-2.7.0/ruby/backward -I/Users/fr$
conftest.c:3:10: fatal error: 'libpq-fe.h' file not found
#include <libpq-fe.h>
         ^~~~~~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
/* end */
user3724786
  • 63
  • 1
  • 9
  • Does this answer your question? [Can't find the 'libpq-fe.h header when trying to install pg gem](https://stackoverflow.com/questions/6040583/cant-find-the-libpq-fe-h-header-when-trying-to-install-pg-gem) – TonyArra Apr 15 '22 at 23:08
  • This link suggests that I do `brew install postgresql`. But this results in: `Error: No such file or directory - /usr/local/var/homebrew/linked/postgresql` – user3724786 Apr 15 '22 at 23:23
  • try `brew cleanup` first – TonyArra Apr 15 '22 at 23:30
  • 1
    You have solved my problem, Tony. I did: ``` $ brew cleanup $ brew install postgresql $ bundle install ``` and now I am able to do migrations. Thanks! – user3724786 Apr 15 '22 at 23:39
  • For me it works without specifying the version like so: ```gem 'pg'``` – Olivier Girardot May 22 '22 at 18:59

1 Answers1

0

The comment by @TonyArra solved my problem.

The solution to the pg gem install problems in Rails can be solved with:

$ brew cleanup 
$ brew install postgresql 
$ bundle install 
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
user3724786
  • 63
  • 1
  • 9