libpq native extension crashed on ruby on rails - ruby-on-rails

i'm trying to install pg ( postgreSQL gem ) on my Mac and got this error
Installing pg 0.18.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /private/var/folders/h5/slvxw4xd0d30dxzxf8vg5c600000gp/T/bundler20160302-7420-1orffo8pg-0.18.1/gems/pg-0.18.1/ext
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20160302-7420-h4zq8h.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--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}/
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/var/folders/h5/slvxw4xd0d30dxzxf8vg5c600000gp/T/bundler20160302-7420-1orffo8pg-0.18.1/extensions/universal-darwin-15/2.0.0/pg-0.18.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /var/folders/h5/slvxw4xd0d30dxzxf8vg5c600000gp/T/bundler20160302-7420-1orffo8pg-0.18.1/gems/pg-0.18.1 for inspection.
Results logged to /var/folders/h5/slvxw4xd0d30dxzxf8vg5c600000gp/T/bundler20160302-7420-1orffo8pg-0.18.1/extensions/universal-darwin-15/2.0.0/pg-0.18.1/gem_make.out
So i check all my packages installed :
Mac OS X El Capitan v10.11.3
$ruby -v
-> ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
$rails -v
-> Rails 4.2.5.1
$brew -v
-> Homebrew 0.9.5 (git revision c9aee; last commit 2016-02-15)
$benv -v
-> rbenv 0.4.0
$postgres -V
-> postgres (PostgreSQL) 9.4.5
$xcode-select -p
/Applications/Xcode.app/Contents/Developer
$gcc --version
-> Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
I don't want to have installed postgre via browser app download, i want it via brew package, so there is a way to install the annoying libpq ?

You shouldn't need libpq for postgres to work with ruby on Mac OSX.
If you installed postgres with Postgres.app, you sould be able to remove it by simply moving postgres.app to the trash can and deleting the data directory from ~/Library/Application Support/Postgres (only if you want to delete all existing postgres databases on your machine)
Then, with homebrew, install postgres via brew install postgresql. The pg gem should work directly with the postgres Homebrew install.

Related

How to install gem pg on mac mini m1?

I'm having trouble installing gem pg on my m1 mac mini. Im trying to host onto Heroku and netlify. Wondering if anyone has found a workaround for this. I have tried several solutions on stack overflow but nothing works.
please help, I consider myself a noob with this kinda stuff.
below is the error im getting.
`
jonathanbleibdrey#Little-Mac listen_to_the_humans % gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /Users/jonathanbleibdrey/.rvm/gems/ruby-2.6.1/gems/pg-1.2.3/ext
/Users/jonathanbleibdrey/.rvm/rubies/ruby-2.6.1/bin/ruby -I /Users/jonathanbleibdrey/.rvm/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0 -r ./siteconf20210323-28582-1dv0k5o.rb extconf.rb
checking for pg_config... yes
Using config values from /opt/homebrew/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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
--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=/Users/jonathanbleibdrey/.rvm/rubies/ruby-2.6.1/bin/$(RUBY_BASE_NAME)
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--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
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/jonathanbleibdrey/.rvm/gems/ruby-2.6.1/extensions/x86_64-darwin-19/2.6.0/pg-1.2.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/jonathanbleibdrey/.rvm/gems/ruby-2.6.1/gems/pg-1.2.3 for inspection.
Results logged to /Users/jonathanbleibdrey/.rvm/gems/ruby-2.6.1/extensions/x86_64-darwin-19/2.6.0/pg-1.2.3/gem_make.out
`
let me know what I can do or resources I can find, or even if we can zoom to fix it wanted to launch it by need of week.
The key to my initial problem getting pg gem to install on my m1 was that installing postgresql via brew did not install a library that the pg gem needs to run. This fixed it:
brew install libpq
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
gem install pg
Figured it out: I had some dependency's in my homebrew that was out of date. all I had to do is
homebrew upgrade
I think.

Rubymine pg install error

Ive been trying out Rubymine for a small rails project and would really like the debugging to work.
The project is a rails API and uses Postgres running on my Mac with El Capitan.
The problem i have is Rubymine is complaining of 'No Rails found in SDK'
I thought the solution to this was to run bundle install from the Rubymine menu.
However that consistently fails at installing pg:
....
Using hashie 3.4.3
Using multi_json 1.11.2
Using multi_xml 0.5.5
Using newrelic_rpm 3.14.2.312
Installing pg 0.18.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20160617-92261-aw26bh.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--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}/
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
extconf failed, exit code 1
...
Using faraday 0.9.2
Using hashie-forbidden_attributes 0.1.1
Using httparty 0.13.7
An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.
I have tried numerous of the other solutions on stack overflow including:
Bundler::GemNotFound: Could not find rake-10.3.2 in any of the sources
An error occurred while installing pg (0.17.1), and Bundler cannot continue
and have installed postgres on my machine (i think) using the app and brew.
Any ideas for making this work would be greatly appreciated!
I don't think the error is RubyMine-related; I think it's system-related.
That is, if you do gem install pg on the command line, I suspect you'll get the same error.
I use rvm and it just works. It installs the necessary system libraries. (That said, others have had difficulties from time to time.)
If you're interested in using rvm, google "install rvm" to get the link for the installation instructions.
That said, you should make sure RubyMine is configured for your project to use the same Ruby you are using on the command line. That way, you will get consistent results in both environments.
Also. just FYI, you can email support#jetbrains.com for RubyMine questions.

Postgres not installing in Bundler (Ruby on Rails)

I am getting pretty desperate, i have tried every answer on the subject but nothing seems to work.
the error log looks like this:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150523-16458-46bzoo.rb extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
sh: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config: No such file or directory
sh: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config: No such file or directory
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--with-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}/
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
extconf failed, exit code 1
Gem files will remain installed in /Users/kevinegstorf/.rvm/gems/ruby-2.0.0-p643/gems/pg-0.18.2 for inspection.
Results logged to /Users/kevinegstorf/.rvm/gems/ruby-2.0.0-p643/extensions/universal-darwin-14/2.0.0/pg-0.18.2/gem_make.out
An error occurred while installing pg (0.18.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.2'` succeeds before bundling.
Installing gem install pg -v '0.18.2' gives me back the same error
I hope someone can help me. tnx
If you already install Postgres.app in Mac,
you should copy /Applications/Postgres.app/Contents/Version/9.4/bin/pg_config to another place. For example /home/pg_config
then run
bundle config build.pg --with-pg-config=/home/pg_config
bundle install
You should find your pg_config file and add it to the build command:
bundle config build.pg --with-pg-config=/usr/local/bin/pg_config
Since your pg_config file is located at /usr/local/bin/pg_config Did you try the command(edited) above?
If that doesn't help maybe try:
env ARCHFLAGS="-arch x86_64" gem install pg

Bundle errors when installing postgres gem

I am trying to install gem pg but keep getting an error returned in my terminal. I have pg installed, i installed it with brew. I ran gem install pg and it just tell me that pg is already installed.
Here is the error I get.
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--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}/
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
Gem files will remain installed in /var/folders/l7/f3_r_hhs46lfprth_1pw57vw0000gn/T/bundler20150320-66140-15yne3b/pg-0.18.1/gems/pg-0.18.1 for inspection.
Results logged to /var/folders/l7/f3_r_hhs46lfprth_1pw57vw0000gn/T/bundler20150320-66140-15yne3b/pg-0.18.1/gems/pg-0.18.1/ext/gem_make.out
An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.1'` succeeds before bundling.
To tell system to use the gem you have installed on machine
Try
brew install postgresql
or try
ARCHFLAGS="-arch x86_64" bundle install
I think I had similar problem on MacOS. Once you installed PostgreSQL viw brew, you need to install pg gem like:
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Check details here. This worked for my MacOS machine.
Good luck!
Here's my fix on ubuntu 20.04:
sudo apt install libpq-dev -y
followed by:
gem install pg -v '0.21.0' --source 'https://rubygems.org/'

can't install postgres ruby gem [duplicate]

This question already has answers here:
Can't find the PostgreSQL client library (libpq)
(23 answers)
Closed 8 years ago.
I am having trouble install postgres on OSX mavericks. I have tried to follow the numerous guides on Stackoverflow with no luck. I installed the postgres.app and also postgres. I have found my pg_config file and tried this command:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
But I am still getting this error
Building native extensions with: '--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config .'
This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config .
Using config values from /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--with-pg
--without-pg
--with-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}/
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/pg-0.17.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-13/2.0.0/pg-0.17.1/gem_make.out
This also seems to be working:
Can't find the PostgreSQL client library (libpq)
$ sudo su
$ env ARCHFLAGS="-arch x86_64" gem install pg
I had the same problem a couple days ago and this worked for me:
brew install libpqxx
Rails 3 - can't install pg gem

Resources