gem install pg --with-pg-config works, bundle fails
Asked Answered
N

18

83

WhenI run (as root)

gem install pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config

I get the following output:

#-> gem instal pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config
Building native extensions.  This could take a while...
Successfully installed pg-0.12.0
1 gem installed
Installing ri documentation for pg-0.12.0...
Installing RDoc documentation for pg-0.12.0...
#-> 

When I run bundle install:

Installing pg (0.12.0) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby 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 ***
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=/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby
--with-pg
--without-pg
--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-pg-config
--without-pg-config
--with-pg_config
--without-pg_config


Gem files will remain installed in /var/www/simpletrac/vendor/cache/ruby/1.9.1/gems/pg-    0.12.0 for inspection.
Results logged to /var/www/simpletrac/vendor/cache/ruby/1.9.1/gems/pg-0.12.0/ext/gem_make.out
An error occured while installing pg (0.12.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.0'` succeeds before bundling.

I have libpq-fe.h installed at /usr/pgsql-9.1/include/libpq-fe.h. So, I tried

gem install pg -v '0.12.0' -- --with-pg-config=/usr/pgsql-9.1/bin/pg_config --with-pg-lib=/usr/pgsql-9.1/include/libpq-fe.h but still no go. 

Any help would be greatly appreciated.

Also, I have installed postgresql91-devel and ruby-devel. Running CentOS 6.

Nichols answered 10/2, 2012 at 21:20 Comment(0)
C
199

Have you tried running this before running bundle install?

bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config

See http://bundler.io/v1.3/bundle_config.html

Cowpea answered 10/2, 2012 at 21:32 Comment(5)
If you're using MacOS + MacPorts, see Lester's post for the solution.Obala
I have same error but I am using mysql database. What will be command pls ??Inadvertent
This seems to have the answer for MySql: https://mcmap.net/q/130807/-bundle-install-problem-mysql-h-is-missingCowpea
Worked like a charm on CentOS 6! Just needed to run also a yum install postgresql-devel before the whole installation fully succeeded!Redcoat
Also --with-pg-dir=/usr/pgsql-<version> handles both config and lib.Watcher
S
23

In case somebody used macports to install postgres and are having problems finding their pg_config, try this:

bundle config build.pg --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config

I hope this helps somebody save some time. Cheers!

Spectrochemistry answered 23/4, 2012 at 8:21 Comment(0)
R
22

If you are not sure where your pg_config is, and assuming you are on Linux or Mac, you can run the following command:

which pg_config

This will return /usr/pgsql-9.1/bin/pg_config

Now use this path as

bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config

And we are ready to go bundle install

Rosin answered 2/2, 2016 at 5:42 Comment(0)
N
11

Copy & Paste:

bundle config build.pg --with-pg-config=`which pg_config` && bundle

Details:

Visit for more information:

The first thing you should do is ensure that the 'pg_config' tool that comes with Postgres is in your path. If it isn't, or the one that's first in your path isn't the one that was installed with the Postgres you want to build against, you can specify the path to it with the –with-pg-config option.

Source: https://github.com/ged/ruby-pg/blob/1f274f68c16f1af1c642db1b9d3d28aef169dc84/ext/extconf.rb#L27

Noddle answered 8/12, 2016 at 16:31 Comment(0)
M
7

Had the same problem, fixed by installing libpq-dev.

Ref: https://bitbucket.org/ged/ruby-pg/issue/83/help-gem-install-pg-failed-on-opensuse-103

Makeshift answered 22/1, 2013 at 16:37 Comment(0)
S
5

You can get this error if you have pg_config installed but its not in any path. You can add it to your PATH env in your ~/.bashrc.

For example.

export PATH=${PATH}:/usr/pgsql-9.2/bin
Superb answered 14/1, 2013 at 16:35 Comment(1)
Could this be a result of installing from source instead of a package manager? Worked for me anyways - Just curious of why I encountered the problem.Gamp
A
5

The Postgres gem can't find the Postgres configuration file. You need to tell it where it is. The most enjoyable solution to this in my opinion is to skip Brew and MacPorts and just use the Postgres app. Download and install from here:

http://postgresapp.com/

Now add the bin folder to your path:

PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

You may also wish to add this to your ~/.bash_profile

Now install the gem:

gem install pg

it should go smoothly.

Antonietta answered 5/11, 2013 at 14:26 Comment(0)
N
4

I'm on Mac and i use Homebrew, so to fix this issue i just installed postgresql with brew:

brew install postgresql

And then installed the gem.

Nazi answered 20/11, 2014 at 7:18 Comment(0)
R
3

I had to do this to fix mine on OS X:

export PATH=/opt/local/lib/postgresql84/bin/:$PATH

And I had to do it despite the fact that I already had this in my path:

[user@foo ~] which psql84
/opt/local/bin/psql84

[user@foo ~] ls -altrh /opt/local/bin/psql84 
lrwxr-xr-x  1 root  admin    36B Dec  7 02:15 /opt/local/bin/psql84 ->  /opt/local/lib/postgresql84/bin/psql

I hope that helps another Mac user with this problem.

Redvers answered 29/1, 2013 at 20:38 Comment(1)
Thanks I have tested this solution on Mac Yosemite.Lesson
N
2

Try this:

yum install libpqxx-devel

It works with Postgr9.2.

Nashoma answered 1/6, 2013 at 21:22 Comment(0)
M
2

I am using Arch Linux, and was having similar problems. Used sudo pacman -S libpqxx and reran then installed the pg gem and then ran bundle install again, and this time it finally worked!

Midkiff answered 26/3, 2015 at 20:7 Comment(2)
I am using Arch Linux as well and this solved my issue!Iraq
2016, postgresql 9.5 and pg 0.18.4 doesn't seem to work with the solution mentioned (I am also using arch linux).Oldie
B
2

Somes cases on UBUNTU

sudo apt-get install libpq-dev

On CentOS 7

sudo yum install postgresql-devel

Then

bundle install

this worked for me.

Bellyache answered 2/8, 2018 at 20:15 Comment(0)
I
1

This link suggested using:

gem install pg --pre

I couldn't get the pg gem to install for days,but this method finally worked for me. Hope this will be helpful.

Intrigant answered 23/1, 2016 at 4:32 Comment(0)
S
1

When do you use postgresapp on Mac, read the http://postgresapp.com/documentation/cli-tools.html documentation and Configure your $PATH. Before this try run the bundle install again.

Sacristan answered 22/3, 2016 at 2:44 Comment(0)
E
1

Make sure you have postgress installed. if not install it first. Using terminal for example.

brew install postgresql

After that run

bundle install
Endsley answered 25/5, 2017 at 14:10 Comment(0)
E
0
gem install pg -v '0.17.1'

Did the trick for me.

Eiser answered 19/3, 2015 at 5:12 Comment(0)
C
0

in OSX, first install pg:

brew install postgresql

second, do gem install:

gem install pg --source 'https://rubygems.org/'

you can then run bundle install

Chelyuskin answered 7/1, 2019 at 16:16 Comment(0)
A
-1

I am using mac and didn't want to install postgresql locally.

Installing libpq and setting the bundler config worked for me.

Reference link

Aldose answered 24/5, 2019 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.