I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error:
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/u/.rvm/rubies/ruby-1.9.2-p0/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
--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=/home/u/.rvm/rubies/ruby-1.9.2-p0/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 /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0 for inspection.
Results logged to /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0/ext/gem_make.out
How do I solve this problem?
It looks like in Ubuntu that header is part of the libpq-dev package (at least in the following Ubuntu versions:
11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04 (Precise Pangolin), 14.04 (Trusty Tahr) and 18.04 (Bionic Beaver)):
...
/usr/include/postgresql/libpq-fe.h
...
So try installing libpq-dev or its equivalent for your OS:
For Ubuntu/Debian systems: sudo apt-get install libpq-dev
On Red Hat Linux (RHEL) systems: yum install postgresql-devel
For Mac Homebrew: brew install postgresql
For Mac MacPorts PostgreSQL: gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
For OpenSuse: zypper in postgresql-devel
For ArchLinux: pacman -S postgresql-libs
On macOS (previously Mac OS X and OS X), use Homebrew to install the proper headers:
brew install postgresql
and then running
gem install pg
should work.
Alternatively, instead of installing the whole postgresql, you can brew install libpq and export the correct PATH and PKG_CONFIG_PATH as explained in the 'Caveats' section
I had also tried doing gem install libpq-dev, but I received this error:
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
However I found that installing with sudo apt-get (which I try to avoid using with Ruby on Rails) worked, i.e.
sudo apt-get install libpq-dev
# or
apt-get install postgres-server-dev-{pg.version}
# for postgresql 9.4 on Ubuntu 14.04
then I was able to do
gem install pg
without issues.
I could solve this in another way. I didn't find the library on my system. Thus I installed it using an app from PostgreSQL main website. In my case (OS X) I found the file under /Library/PostgreSQL/9.1/include/ once the installation was over. You may also have the file somewhere else depending on your system if you already have PostgreSQL installed.
Thanks to this link on how to add an additional path for gem installation, I could point the gem to the lib with this command:
export CONFIGURE_ARGS="with-pg-include=/Library/PostgreSQL/9.1/include/"
gem install pg
After that, it works, because it now knows where to find the missing library. Just replace the path with the right location for your libpq-fe.h
Can't find the libpq-fe.h header
i had success on CentOS 7.0.1406 running the following commands:
~ % psql --version # => psql (PostgreSQL) 9.4.1
yum install libpqxx-devel
gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config
Alternatively, you can configure bundler to always install pg with these options (helpful for running bundler in deploy environments),
bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config
For CentOS 6.4,
yum install postgresql-devel
gem install pg
worked well!
Just for the record:
Ruby on Rails 4 application in OS X with PostgresApp (in this case 0.17.1 version needed - kind of an old project):
gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
It is only issue of missing libpq-fe.h
On ubuntu we just need to run:
sudo apt-get install libpq-dev
Above command will install a NEW package libpq-dev and after that you can again execute bundle install to resume your bundle installation.
On Mac OS X run like this:
gem install pg -- --with-pg-config=***/path/to/pg_config***
***/path/to/pg_config*** is path to pg_config
In my case it was package postgresql-server-dev-8.4 (I am on Ubuntu 11.04 (Natty Narwhal), 64 bits).
For MacOS without installing PostgreSQL server:
brew install libpq
gem install pg -- --with-pg-config="/usr/local/Cellar/libpq/9.6.6/bin/pg_config"
The right answer for Mac users with Postgres.app is to build against the libpq provided with that package. For example, with the 9.4 release (current as of this writing), all you need is:
export CONFIGURE_ARGS="with-pg-include=/Applications/Postgres.app/Contents/Versions/9.4/include"
gem install pg
This will keep your pg gem in sync with exactly the version of PostgreSQL you have installed. Installing something from Homebrew is a waste in this case.
I had the same issue on Amazon Linux. I could find the header libpq-fe.h, but somehow it didn't work.
It came from the different versions of the packages that were installed through the different users on the machine. PostgreSQL 9.2 and PostgreSQL 9.3 were installed. So, make sure of your PostgreSQL version before including the libraries.
For me, the magic command line was:
sudo yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel
Source: An almost idiot's guide to install PostgreSQL 9.3, PostGIS 2.1 and pgRouting with Yum
My solution for Fedora 30:
sudo dnf install /usr/include/libpq-fe.h
A more general answer for any Debian-based distribution (which includes Ubuntu) is the following. First, install the apt-file package running as root:
apt-get install apt-file
This allows you to search for packages containing a file. Then, update its database using
apt-file update
(this can be run as normal user). Then, look for the missing header using:
apt-file search libpq-fe.h
On my machine, this gives:
libpq-dev: /usr/include/postgresql/libpq-fe.h
postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h
There you go !
On Ubuntu, install the "libpq-dev" to get rid of this issue.
sudo apt-get install libpq-dev
On Fedora 32, I managed to solve this same issue by installing libpq5-devel specifically.
If you install postgresql from the official repository, you will have several versions that won't fix the problem, so it's really a matter of trying out which one it needs.
I had the same problem on Mac OS, but I installed the PostgreSQL gem easily by using the following in a terminal:
ARCHFLAGS="-arch x86_64" gem install pg
(I installed PostgreSQL first with brew install postgresql.)
I found this answer, and it was the only one that worked for me (Mac OS) - after researching for about two days:
$ sudo su
$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions. This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...
See Stack Overflow question Can't find the PostgreSQL client library (libpq).
I recently upgraded to Mac OS X v10.10 (Yosemite) and was having difficulty building the pg gem.
The error reported was the typical:
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***
My solution was to gem uninstall pg and then bundle update pg to replace the gem with the latest. I did run brew update; brew upgrade after the Yosemite install to get the latest versions of packages I had installed previously.
On a Mac, I solved it using this code:
gem install pg -v '0.18.4' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
I had this issue with Postgresql 9.6. I was able to fix it by doing:
brew upgrade postgresql#9.6
brew link postgresql#9.6 --force
gem install pg
I am running Postgres.app on a Mac and I had to
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
first. Then
bundle install
worked for me.
I encountered the same error with postgres installed through asdf. The pg-config solutions didn't work for me. Instead I had to locate the postgres include folder which contains the file and run the command with the --with-pg-include flag
gem install pg -- --with-pg-include=/<path>/.asdf/installs/postgres/<version>/include
On CentOS,I installed libpq-dev package using below command
yum install postgresql-devel
Executing gem install pg returned the same error as "No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config".
Installing the gem as below solved my problem
gem install pg -- --with-pg-config=/usr/pgsql-x.x/bin/pg_config
On Ubuntu 20.04, I already had libpq5:amd64 version 13.2-1.pgdg20.04+1. Now when I tried to install libpq-dev from apt repository, I was receiving
The following packages have unmet dependencies:
libpq-dev : Depends: libpq5 (= 12.6-0ubuntu0.20.04.1) but 13.2-1.pgdg20.04+1 is to be installed
I grabbed the deb from http://ftp.us.debian.org/debian/pool/main/p/postgresql-13/libpq-dev_13.2-1_amd64.deb and did the following:
mkdir -p /tmp/libpq-dev
dpkg-deb -R libpq-dev_13.2-1_amd64.deb /tmp/libpq-dev
sed -i 's|= 13.2-1|= 13.2-1.pgdg20.04+1|' /tmp/libpq-dev/DEBIAN/control
dpkg-deb -b /tmp/libpq-dev /tmp/libpq-dev-new.deb
sudo dpkg -i /tmp/libpq-dev-new.deb
I have been using the gem happily after that. No additional installs or anything.
For alpine, please use below to fix the error
apk add --no-cache postgresql-dev
On debian bullseye, none of the existing answers solved the issue for me.
In case it helps someone with the same configuration as mine:
Use PostgreSQL's apt repository: https://wiki.postgresql.org/wiki/Apt
sudo apt-get update && sudo apt-get dist-upgrade (upgrade PostgreSQL from v13 to v14)
sudo apt-get install libpq-dev
gem install pg or bundle install
On FreeBSD (9.1) the necessary package is /usr/ports/database/postgresql-server* which when installed will also install the required header file that makes the gem install of "pg" fail. This answer here helped me find the solution but the difference in package names required a bit of searching.
Hopefully this helps someone avoid a bit of head scratching when searching for the "-dev" package on a FreeBSD system!
On Debian 7.0, 64-bit (Wheezy), just run:
sudo apt-get install libpq-dev
After you successfully installed libpq-dev, run:
bundle install
Related
I'm trying to install PostgreSQL's pg gem for Ruby.
I issued the following command:
gem install pg
I installed Ruby 1.9.2 using RVM.
The above command shows me the following error.
The error is :
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby extconf.rb
checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.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=/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby
--with-pg
--without-pg
--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
--enable-static-build
--disable-static-build
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0/ext/gem_make.out
I don't know what is the error...
You need install the postgreSQL dev package with header of PostgreSQL
sudo apt-get install libpq-dev
After reading and thrashing around for 2 days, and trying many things found in other notes the following single line was the cure for me on Ubuntu Lucid 10.04 mixed with some Maverick packages and RVM (ruby 1.9.2-p290, rvm 1.10.2 rubygems 1.8.15, rails 3.0.1, postgres 8.4.10) :
gem install pg -- --with-pg-lib=/usr/lib
the result:
Building native extensions. This could take a while...
Successfully installed pg-0.13.1
1 gem installed
Installing ri documentation for pg-0.13.1...
Installing RDoc documentation for pg-0.13.1...
{yea - finally success} !!
!note that the output from running pg_config lacks the item -lpq in the LIBS variable on my Ubuntu / Postresql install!!
and why the switch from pq to pg in certain places -- confusing to newbie ??
the thing I still do not understand is the double set of -- and --with(option
but I'm way beyond my depth anyway
In Ubuntu this works for me, I hope help you:
sudo apt-get install libpq-dev
and
gem install pg -- --with-pg-lib=/usr/lib
I'm on Ubuntu 12.10 and running this command:
apt-get install libpq-dev
helped me - after that ran gem install pg -v "0.14.1", and all good now
Installing libpq-dev did not work for me. I also needed to install build-essential
sudo apt-get install libpq-dev build-essential
Need to add package
sudo apt-get install libpq-dev
to install pg gem in RoR
Simple solution for ubuntu users...
First uninstall all postgres packages, then run these commads...
sudo apt-get install postgresql
sudo apt-get install postgresql-client libpq5 libpq-dev
# for rvm (single user)
mv ~/.rvm/usr/lib ~/.rvm/usr/lib_rvm
# for rvm (multi-user)
mv /usr/local/rvm/usr/lib /usr/local/rvm/usr/lib_rvm
gem install pg -- --with-pg-lib=/usr/lib
Then run 'bundle install'. Every thing will be fine. Have a good day!
sudo apt-get install postgresql-client libpq5 libpq-dev then do gem install pg
For .RVM users it will be better:
rvmsudo gem install pg -- --with-pg-lib=/usr/lib
it worked for me (after i saw jdupont version)
If you have libpq-dev installed and are still having this problem it is likely due to conflicting versions of OpenSSL's libssl and friends - the Ubuntu system version in /usr/lib (which libpq is built against) and a second version RVM installed in $HOME/.rvm/usr/lib (or /usr/local/rvm/usr/lib if it's a system install). You can verify this by temporarily renaming $HOME/.rvm/usr/lib and seeing if "gem install pg" works.
To solve the problem have rvm rebuild using the system OpenSSL libraries (you may need to manually remove libssl.* and libcrypto.* from the rvm/usr/lib dir):
rvm reinstall 1.9.3 --with-openssl-dir=/usr
This finally solved the problem for me on Ubunto 12.04.
Try this
sudo apt-get install postgresql postgresql-contrib libpq-dev
You should install PG Database server in the first place to install clients. Afterwards, you install clients.
See this blog post to know about setting up PostGresSQL for the first time for Ruby on Rails development.
This solved the problem for me on Ubuntu 12.04 after every suggestion here had failed.
rvmsudo gem install pg -v '0.12.2' -- --with-pg-lib=/usr/include/postgresql
I was trying to setup a Rails project in my freshly installed Ubuntu 16.04. I ran into the same issue while running bundle. Running
sudo apt-get install aptitude
followed by
sudo apt-get install libpq-dev
Solved it for me.
For anyone who is still having issues after trying all the answers on this page, the following (finally) worked:
sudo apt-get install libgmp3-dev
gem install pg
This was after doing everything else mentioned on this page.
postgresql 9.5.8
Ubuntu 16.10
Another solution to this problem is to install PostgreSQL using Homebrew/linuxbrew:
brew install postgresql
As a matter of habit I don't like to use sudo unless I have to.
For those trying to install Redmine, I missed sudo apt-get install ruby-all-dev after trying all of the above.
Initial error being mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h.
I had the same problem, and tried a lot of different variants. After some tries I became able to sudo gem install, but still have problem to install it without sudo.
Finally I found a decission - reinstalling of rvm helped me. Probably it can save time somebody else.
apt-get install ruby-dev worked for me.
Another option is to use Homebrew which works on Linux and macOS to install just the supporting libraries:
brew install libpq
then
brew link libpq --force
(the --force option is required because it conflicts with the postgres formula.)
I'm trying to install PostgreSQL's pg gem for Ruby.
I issued the following command:
gem install pg
I installed Ruby 1.9.2 using RVM.
The above command shows me the following error.
The error is :
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby extconf.rb
checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.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=/home/User/.rvm/rubies/ruby-1.9.2-preview3/bin/ruby
--with-pg
--without-pg
--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
--enable-static-build
--disable-static-build
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.2-preview3/gems/pg-0.9.0/ext/gem_make.out
I don't know what is the error...
You need install the postgreSQL dev package with header of PostgreSQL
sudo apt-get install libpq-dev
After reading and thrashing around for 2 days, and trying many things found in other notes the following single line was the cure for me on Ubuntu Lucid 10.04 mixed with some Maverick packages and RVM (ruby 1.9.2-p290, rvm 1.10.2 rubygems 1.8.15, rails 3.0.1, postgres 8.4.10) :
gem install pg -- --with-pg-lib=/usr/lib
the result:
Building native extensions. This could take a while...
Successfully installed pg-0.13.1
1 gem installed
Installing ri documentation for pg-0.13.1...
Installing RDoc documentation for pg-0.13.1...
{yea - finally success} !!
!note that the output from running pg_config lacks the item -lpq in the LIBS variable on my Ubuntu / Postresql install!!
and why the switch from pq to pg in certain places -- confusing to newbie ??
the thing I still do not understand is the double set of -- and --with(option
but I'm way beyond my depth anyway
In Ubuntu this works for me, I hope help you:
sudo apt-get install libpq-dev
and
gem install pg -- --with-pg-lib=/usr/lib
I'm on Ubuntu 12.10 and running this command:
apt-get install libpq-dev
helped me - after that ran gem install pg -v "0.14.1", and all good now
Installing libpq-dev did not work for me. I also needed to install build-essential
sudo apt-get install libpq-dev build-essential
Need to add package
sudo apt-get install libpq-dev
to install pg gem in RoR
Simple solution for ubuntu users...
First uninstall all postgres packages, then run these commads...
sudo apt-get install postgresql
sudo apt-get install postgresql-client libpq5 libpq-dev
# for rvm (single user)
mv ~/.rvm/usr/lib ~/.rvm/usr/lib_rvm
# for rvm (multi-user)
mv /usr/local/rvm/usr/lib /usr/local/rvm/usr/lib_rvm
gem install pg -- --with-pg-lib=/usr/lib
Then run 'bundle install'. Every thing will be fine. Have a good day!
sudo apt-get install postgresql-client libpq5 libpq-dev then do gem install pg
For .RVM users it will be better:
rvmsudo gem install pg -- --with-pg-lib=/usr/lib
it worked for me (after i saw jdupont version)
If you have libpq-dev installed and are still having this problem it is likely due to conflicting versions of OpenSSL's libssl and friends - the Ubuntu system version in /usr/lib (which libpq is built against) and a second version RVM installed in $HOME/.rvm/usr/lib (or /usr/local/rvm/usr/lib if it's a system install). You can verify this by temporarily renaming $HOME/.rvm/usr/lib and seeing if "gem install pg" works.
To solve the problem have rvm rebuild using the system OpenSSL libraries (you may need to manually remove libssl.* and libcrypto.* from the rvm/usr/lib dir):
rvm reinstall 1.9.3 --with-openssl-dir=/usr
This finally solved the problem for me on Ubunto 12.04.
Try this
sudo apt-get install postgresql postgresql-contrib libpq-dev
You should install PG Database server in the first place to install clients. Afterwards, you install clients.
See this blog post to know about setting up PostGresSQL for the first time for Ruby on Rails development.
This solved the problem for me on Ubuntu 12.04 after every suggestion here had failed.
rvmsudo gem install pg -v '0.12.2' -- --with-pg-lib=/usr/include/postgresql
I was trying to setup a Rails project in my freshly installed Ubuntu 16.04. I ran into the same issue while running bundle. Running
sudo apt-get install aptitude
followed by
sudo apt-get install libpq-dev
Solved it for me.
For anyone who is still having issues after trying all the answers on this page, the following (finally) worked:
sudo apt-get install libgmp3-dev
gem install pg
This was after doing everything else mentioned on this page.
postgresql 9.5.8
Ubuntu 16.10
Another solution to this problem is to install PostgreSQL using Homebrew/linuxbrew:
brew install postgresql
As a matter of habit I don't like to use sudo unless I have to.
For those trying to install Redmine, I missed sudo apt-get install ruby-all-dev after trying all of the above.
Initial error being mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h.
I had the same problem, and tried a lot of different variants. After some tries I became able to sudo gem install, but still have problem to install it without sudo.
Finally I found a decission - reinstalling of rvm helped me. Probably it can save time somebody else.
apt-get install ruby-dev worked for me.
Another option is to use Homebrew which works on Linux and macOS to install just the supporting libraries:
brew install libpq
then
brew link libpq --force
(the --force option is required because it conflicts with the postgres formula.)
I'm trying to install the pg gem in order to work again with my rails projects. But I get this error:
Building native extensions. This could take a while... ERROR: Error
installing pg: ERROR: Failed to build gem native extension.
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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 --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=/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
--with-pg --without-pg --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}/
Gem files will remain installed in
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0
for inspection. Results logged to
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out
I tried everything I found on stackoverflow but I still get this error.
If I try to install postgresql using brew I get the following waring:
Warning: postgresql-9.2.4 already installed, it's just not linked
If I try to link
brew link postgresql Linking /usr/local/Cellar/postgresql/9.2.4...
Warning: Could not link postgresql. Unlinking...
Error: Could not symlink file:
/usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7
/usr/local/share/man/man7 is not writable. You should change its
permissions.
Help Please
NOTE: I already installed the command line tools for mavericks.
If I uninstall using homebrew and try to install again, I get this error:
==> Downloading http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2
################################################################## 100.0%
==> Patching patching file src/pl/plpython/Makefile patching file contrib/uuid-ossp/uuid-ossp.c
==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local/Cellar/p
==> make install-world
==> Caveats
Build Notes
If builds of PostgreSQL 9 are failing and you have version 8.x
installed, you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510
Create/Upgrade a Database
If this is your first install, create a database with: initdb
/usr/local/var/postgres -E utf8
To migrate existing data from a previous major version (pre-9.2) of
PostgreSQL, see:
http://www.postgresql.org/docs/9.2/static/upgrading.html
Loading Extensions
By default, Homebrew builds all available Contrib extensions. To see a
list of all available extensions, from the psql command line, run:
SELECT * FROM pg_available_extensions;
To load any of the extension names, navigate to the desired database
and run: CREATE EXTENSION [extension name];
For instance, to load the tablefunc extension in the current database,
run: CREATE EXTENSION tablefunc;
For more information on the CREATE EXTENSION command, see:
http://www.postgresql.org/docs/9.2/static/sql-createextension.html For
more information on extensions, see:
http://www.postgresql.org/docs/9.2/static/contrib.html
Other
Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC
When installing the postgres gem, including ARCHFLAGS is recommended:
ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't
want/need launchctl, you can just run:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Warning: Could not link
postgresql. Unlinking... Error: The brew link step did not complete
successfully The formula built, but is not symlinked into /usr/local
You can try again using `brew link postgresql'
==> Summary 🍺 /usr/local/Cellar/postgresql/9.2.4: 2831 files, 38M, built in 4.9 minutes
SOLUTION:
I execute this command in order to change the permission of the folder:
sudo chown jeanosorio /usr/local/share/man/man7
Then
brew link postgresql Linking /usr/local/Cellar/postgresql/9.3.1... 421
symlinks created
And finally:
sudo ARCHFLAGS="-arch x86_64" gem install pg
Fetching: pg-0.17.0.gem (100%) Building native extensions. This could
take a while... Successfully installed pg-0.17.0
If you want to avoid using MacPorts, you can download the Postgres App and place it into the Application directory.
Then, specify the location of newly downloaded pg_config:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
If you run in to missing headers problem, try specifying the include directory of the app:
gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/Versions/latest/include/'
Use brew to get postgresql
brew install postgresql
Check you have pg_config in the installed brew. I found mine in
/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Check via :
$ ls /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
> /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Once done, install the pg gem with
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
I wasn't able to install postgres via MacPorts. Instead, I installed Postgress.app. and called
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Note: in newer versions (in 9.3 at least) the path is actually: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
If you have homebrew, just type:
$ brew install postgresql
For me, on Yosemite, I didn't need to specify pg_config path. The following got it done.
brew install postgresql
sudo env ARCHFLAGS="-arch x86_64" gem install pg
Seems like architecture flag is the key.
Here's another alternative in case you want to use the postgresql installer directly. There's a couple of hoops you gotta jump through to begin with after updating to mavericks. Here's what I did:
Install the xcode command line tools first:
xcode-select --install
Download and install the latest version of PostgreSQL (9.3.1), in my case I just used the graphical installer. Here's the link to the downloads page:
http://www.enterprisedb.com/products-services-training/pgdownload#osx
Just choose all of the defaults it gives you. It my case it installed postgres to the following directory, if you installed it to a different directory, just remember the path you chose, because you'll need it shortly.
/Library/PostgreSQL/9.3
If you now try and install the latest pg gem (0.17.0) you'll need to pass a couple of options on the command line. This is what I used:
ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
If you installed postgres to a different location then you'll need to fix up the path to the pg_config file.
If it complains of a missing 'libpq.5.dylib' file while trying install the pg gem you'll need to create a symlink pointing to the actual location of this file. Postgres is looking for it in your /usr/local/lib/ directory so create a symlink in there and redirect it to its actual location. In my case I had to run:
sudo ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib /usr/local/lib/libpq.5.dylib
Once you've done that, retry installing the gem again and hopefully it will work for you the same way it did for me.
In my case (i needed PG 0.16.0 on Mavericks), i installed postgresql via MacPorts
sudo port install postgresql90
and then
gem install pg -v '0.16.0' -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
For the latest version you need to deduct -v '0.16.0'
gem install pg -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
If you have Homebrew installed do not install MacPorts before you read about their coexistense
Place the missing --with-pg-config in Bundler's config file: /Users/<your_user>/.bundle/config to make your life easier.
---
BUNDLE_BUILD__PG: --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
BUNDLE_BUILD__EXAMPLE_GEM: --other-configs
BUNDLE_BUILD__OTHER_EXAMPLE_GEM: --other-configs
Then run bundle install again.
That works for me! (Postgres 93, mac ox 10.9.1)1. download # http://postgresapp.com/ and than
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
I was stuck on my bundle install for 3 days. Tried Everything like adding env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config
I was able to see pg gem getting installed after this command but still it was not installing from bundle install, which was a pain because I dint know what to write in Gemfile except gem 'pg'
The thing which finally worked for me was to find that my pg_config was in /Library/PostgreSQL/9.3/bin/pg_config and by default the Gemfile bundle install looks in /usr/local/bin/pg_config
I just ran the following command and magic happened.
bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case it didn't work if you don't specify the arch flags, OS X 10.10.3 and postersApp 9.4
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- \--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
The easiest way for me to resolve this was to use Postgres.app and set up my env vars so gem install pg just works (instead of requiring the --with-pg-config flag).
Using Homebrew Cask,
brew cask install postgres
echo 'export PG_HOME=/Applications/Postgres.app/Contents/Versions/latest' >> ~/.bash_profile
echo 'export PATH="$PATH:$PG_HOME/bin"' >> ~/.bash_profile
source ~/.bash_profile
# now it just works
gem install pg
This is what it worked for me:
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case, I uninstalled the version installed via homebrew and switched to Postgres.app (v9.3.4.2 at the time of writing).
It only seemed to work when prepending the environment architecture flags and specifying the path to pg_config. Your milage might vary, so this answer could help with variations on pg_config's location.
Here is the final, complete command that worked for me:
env ARCHFLAGS="-arch x86_64" gem install pg -- \
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
I had installed postgres using homebrew on mac. Used below command to find the location
which postgres
/usr/local/opt/postgresql#12/bin/postgres
Installed gem using below command. In the above path just replace the postgres with pg_config since command requires path for pg_config.
gem install pg -- --with-pg-config=/usr/local/opt/postgresql#12/bin/pg_config
I was getting the same error when running bundle install regarding the pg gem (using Mac OS X Mavericks). After hours of researching, I found the solution. I installed postgres using homebrew
brew install postgres
After installing that, I created a new rails app using postgres. I ran
bundle install
to no avail (got same error as the question). I used
which psql
to figure out where my postgres was installed, it returned
/usr/local/bin/psql
before running bundle install again, I had to change the global path to build.pg by running the following
bundle config build.pg --with-pg-config=/usr/local/bin/pg_config
then I ran bundle install again and voila! I used the postgres where brew installed it.
On OS X Mavericks with latest Postgres App do the following with sudo privileges
env ARCHFLAGS="-arch x86_64" gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
What worked for me on 10.9.3 with Xcode 5.1.1 was the following:
brew update
brew install postgresql
gem install pg -v '0.17.1'
I needed pg 0.17.1
For me, the error message looked like this:
Installing pg 0.18.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
As the error message shows, it's trying to execute the command/script "pg_config". So just add it to the path from wherever your Postgres installation is. In my case, I did:
export PATH=/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH
then
bundle
That's it.
For any lost soul outthere still having this issue with no resolution and have a brew installed ruby and postgres. Here's the following steps to make sure of:
Make sure your version of ruby wasn't installed with the --universal flag.
This was the hardest thing to figure out, I had --universal which was the final root of the problem.
Make sure you have initialized postgresql properly with initdb and createdb commands (look elsewhere for steps to do this).
Make sure Xcode (Optional) and command line tools is installed; on the terminal:
xcode-select --install
sudo xcodebuild -license (if Xcode installed) or open the application and accept the license agreement.
Reboot Computer
which ruby, which gem and which postgres should show /usr/local/bin/ruby, /usr/local/bin/gem and /usr/local/bin/postgres respectfully.
On the terminal run:
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
or
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Making sure all these steps are satisfied I was able to solve the following errors:
ruby.h header error
developer tools installed first error
First of all find pg_config location
sudo find / -name "pg_config" -print
The answer is /Library/PostgreSQL/9.1/bin/pg_config in my configuration (MAC Maverick)
Then try installing something like below
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
if this does not work then try to check in what way you installed postgresql
brew/mac port/setup
then you have to try relevant option to the same.
Thank you.
Ram
I was with the same problem, this was the solution I've found.
If you run brew doctor, it will tell you that probably you have installed something without brew that have changed the permissions on some folders, and so, you need to change permissions back to you on that folder.
Inside /usr/local/share/man, what you can do is the following:
sudo chown [yourusername] man7
And then:
brew link postgres
Hope it helps!
Similarly, after installing Mavericks 'bundle update' was throwing an error on the pg gem, which is only used on production and not locally.
I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.
The fix was to just 'brew uninstall postgresql', then 'brew install postgresql'. After which I was immediately able to successfully run 'bundle update'
Postgres 9.4:
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/Versions/9.4/bin/pg_config
sudo su
then
ARCHFLAGS="-arch x86_64" gem install pg -v '0.18'
worked on 10.10.2
If after trying everything here it still won't install, try opening Xcode and accepting the license agreement.
I'm trying to install the pg gem in order to work again with my rails projects. But I get this error:
Building native extensions. This could take a while... ERROR: Error
installing pg: ERROR: Failed to build gem native extension.
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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 --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=/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
--with-pg --without-pg --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}/
Gem files will remain installed in
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0
for inspection. Results logged to
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out
I tried everything I found on stackoverflow but I still get this error.
If I try to install postgresql using brew I get the following waring:
Warning: postgresql-9.2.4 already installed, it's just not linked
If I try to link
brew link postgresql Linking /usr/local/Cellar/postgresql/9.2.4...
Warning: Could not link postgresql. Unlinking...
Error: Could not symlink file:
/usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7
/usr/local/share/man/man7 is not writable. You should change its
permissions.
Help Please
NOTE: I already installed the command line tools for mavericks.
If I uninstall using homebrew and try to install again, I get this error:
==> Downloading http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2
################################################################## 100.0%
==> Patching patching file src/pl/plpython/Makefile patching file contrib/uuid-ossp/uuid-ossp.c
==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local/Cellar/p
==> make install-world
==> Caveats
Build Notes
If builds of PostgreSQL 9 are failing and you have version 8.x
installed, you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510
Create/Upgrade a Database
If this is your first install, create a database with: initdb
/usr/local/var/postgres -E utf8
To migrate existing data from a previous major version (pre-9.2) of
PostgreSQL, see:
http://www.postgresql.org/docs/9.2/static/upgrading.html
Loading Extensions
By default, Homebrew builds all available Contrib extensions. To see a
list of all available extensions, from the psql command line, run:
SELECT * FROM pg_available_extensions;
To load any of the extension names, navigate to the desired database
and run: CREATE EXTENSION [extension name];
For instance, to load the tablefunc extension in the current database,
run: CREATE EXTENSION tablefunc;
For more information on the CREATE EXTENSION command, see:
http://www.postgresql.org/docs/9.2/static/sql-createextension.html For
more information on extensions, see:
http://www.postgresql.org/docs/9.2/static/contrib.html
Other
Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC
When installing the postgres gem, including ARCHFLAGS is recommended:
ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't
want/need launchctl, you can just run:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Warning: Could not link
postgresql. Unlinking... Error: The brew link step did not complete
successfully The formula built, but is not symlinked into /usr/local
You can try again using `brew link postgresql'
==> Summary 🍺 /usr/local/Cellar/postgresql/9.2.4: 2831 files, 38M, built in 4.9 minutes
SOLUTION:
I execute this command in order to change the permission of the folder:
sudo chown jeanosorio /usr/local/share/man/man7
Then
brew link postgresql Linking /usr/local/Cellar/postgresql/9.3.1... 421
symlinks created
And finally:
sudo ARCHFLAGS="-arch x86_64" gem install pg
Fetching: pg-0.17.0.gem (100%) Building native extensions. This could
take a while... Successfully installed pg-0.17.0
If you want to avoid using MacPorts, you can download the Postgres App and place it into the Application directory.
Then, specify the location of newly downloaded pg_config:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
If you run in to missing headers problem, try specifying the include directory of the app:
gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/Versions/latest/include/'
Use brew to get postgresql
brew install postgresql
Check you have pg_config in the installed brew. I found mine in
/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Check via :
$ ls /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
> /usr/local/Cellar/postgresql/9.3.3/bin/pg_config
Once done, install the pg gem with
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.3/bin/pg_config
I wasn't able to install postgres via MacPorts. Instead, I installed Postgress.app. and called
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Note: in newer versions (in 9.3 at least) the path is actually: /Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
If you have homebrew, just type:
$ brew install postgresql
For me, on Yosemite, I didn't need to specify pg_config path. The following got it done.
brew install postgresql
sudo env ARCHFLAGS="-arch x86_64" gem install pg
Seems like architecture flag is the key.
Here's another alternative in case you want to use the postgresql installer directly. There's a couple of hoops you gotta jump through to begin with after updating to mavericks. Here's what I did:
Install the xcode command line tools first:
xcode-select --install
Download and install the latest version of PostgreSQL (9.3.1), in my case I just used the graphical installer. Here's the link to the downloads page:
http://www.enterprisedb.com/products-services-training/pgdownload#osx
Just choose all of the defaults it gives you. It my case it installed postgres to the following directory, if you installed it to a different directory, just remember the path you chose, because you'll need it shortly.
/Library/PostgreSQL/9.3
If you now try and install the latest pg gem (0.17.0) you'll need to pass a couple of options on the command line. This is what I used:
ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
If you installed postgres to a different location then you'll need to fix up the path to the pg_config file.
If it complains of a missing 'libpq.5.dylib' file while trying install the pg gem you'll need to create a symlink pointing to the actual location of this file. Postgres is looking for it in your /usr/local/lib/ directory so create a symlink in there and redirect it to its actual location. In my case I had to run:
sudo ln -s /Library/PostgreSQL/9.3/lib/libpq.5.dylib /usr/local/lib/libpq.5.dylib
Once you've done that, retry installing the gem again and hopefully it will work for you the same way it did for me.
In my case (i needed PG 0.16.0 on Mavericks), i installed postgresql via MacPorts
sudo port install postgresql90
and then
gem install pg -v '0.16.0' -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
For the latest version you need to deduct -v '0.16.0'
gem install pg -- --with-pg-config=/opt/local/lib/postgresql90/bin/pg_config
If you have Homebrew installed do not install MacPorts before you read about their coexistense
Place the missing --with-pg-config in Bundler's config file: /Users/<your_user>/.bundle/config to make your life easier.
---
BUNDLE_BUILD__PG: --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
BUNDLE_BUILD__EXAMPLE_GEM: --other-configs
BUNDLE_BUILD__OTHER_EXAMPLE_GEM: --other-configs
Then run bundle install again.
That works for me! (Postgres 93, mac ox 10.9.1)1. download # http://postgresapp.com/ and than
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
I was stuck on my bundle install for 3 days. Tried Everything like adding env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config
I was able to see pg gem getting installed after this command but still it was not installing from bundle install, which was a pain because I dint know what to write in Gemfile except gem 'pg'
The thing which finally worked for me was to find that my pg_config was in /Library/PostgreSQL/9.3/bin/pg_config and by default the Gemfile bundle install looks in /usr/local/bin/pg_config
I just ran the following command and magic happened.
bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case it didn't work if you don't specify the arch flags, OS X 10.10.3 and postersApp 9.4
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- \--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
The easiest way for me to resolve this was to use Postgres.app and set up my env vars so gem install pg just works (instead of requiring the --with-pg-config flag).
Using Homebrew Cask,
brew cask install postgres
echo 'export PG_HOME=/Applications/Postgres.app/Contents/Versions/latest' >> ~/.bash_profile
echo 'export PATH="$PATH:$PG_HOME/bin"' >> ~/.bash_profile
source ~/.bash_profile
# now it just works
gem install pg
This is what it worked for me:
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
In my case, I uninstalled the version installed via homebrew and switched to Postgres.app (v9.3.4.2 at the time of writing).
It only seemed to work when prepending the environment architecture flags and specifying the path to pg_config. Your milage might vary, so this answer could help with variations on pg_config's location.
Here is the final, complete command that worked for me:
env ARCHFLAGS="-arch x86_64" gem install pg -- \
--with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
sudo ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
I had installed postgres using homebrew on mac. Used below command to find the location
which postgres
/usr/local/opt/postgresql#12/bin/postgres
Installed gem using below command. In the above path just replace the postgres with pg_config since command requires path for pg_config.
gem install pg -- --with-pg-config=/usr/local/opt/postgresql#12/bin/pg_config
I was getting the same error when running bundle install regarding the pg gem (using Mac OS X Mavericks). After hours of researching, I found the solution. I installed postgres using homebrew
brew install postgres
After installing that, I created a new rails app using postgres. I ran
bundle install
to no avail (got same error as the question). I used
which psql
to figure out where my postgres was installed, it returned
/usr/local/bin/psql
before running bundle install again, I had to change the global path to build.pg by running the following
bundle config build.pg --with-pg-config=/usr/local/bin/pg_config
then I ran bundle install again and voila! I used the postgres where brew installed it.
On OS X Mavericks with latest Postgres App do the following with sudo privileges
env ARCHFLAGS="-arch x86_64" gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
What worked for me on 10.9.3 with Xcode 5.1.1 was the following:
brew update
brew install postgresql
gem install pg -v '0.17.1'
I needed pg 0.17.1
For me, the error message looked like this:
Installing pg 0.18.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
As the error message shows, it's trying to execute the command/script "pg_config". So just add it to the path from wherever your Postgres installation is. In my case, I did:
export PATH=/Applications/Postgres.app/Contents/Versions/9.5/bin:$PATH
then
bundle
That's it.
For any lost soul outthere still having this issue with no resolution and have a brew installed ruby and postgres. Here's the following steps to make sure of:
Make sure your version of ruby wasn't installed with the --universal flag.
This was the hardest thing to figure out, I had --universal which was the final root of the problem.
Make sure you have initialized postgresql properly with initdb and createdb commands (look elsewhere for steps to do this).
Make sure Xcode (Optional) and command line tools is installed; on the terminal:
xcode-select --install
sudo xcodebuild -license (if Xcode installed) or open the application and accept the license agreement.
Reboot Computer
which ruby, which gem and which postgres should show /usr/local/bin/ruby, /usr/local/bin/gem and /usr/local/bin/postgres respectfully.
On the terminal run:
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
or
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Making sure all these steps are satisfied I was able to solve the following errors:
ruby.h header error
developer tools installed first error
First of all find pg_config location
sudo find / -name "pg_config" -print
The answer is /Library/PostgreSQL/9.1/bin/pg_config in my configuration (MAC Maverick)
Then try installing something like below
gem install pg -- --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
if this does not work then try to check in what way you installed postgresql
brew/mac port/setup
then you have to try relevant option to the same.
Thank you.
Ram
I was with the same problem, this was the solution I've found.
If you run brew doctor, it will tell you that probably you have installed something without brew that have changed the permissions on some folders, and so, you need to change permissions back to you on that folder.
Inside /usr/local/share/man, what you can do is the following:
sudo chown [yourusername] man7
And then:
brew link postgres
Hope it helps!
Similarly, after installing Mavericks 'bundle update' was throwing an error on the pg gem, which is only used on production and not locally.
I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.
The fix was to just 'brew uninstall postgresql', then 'brew install postgresql'. After which I was immediately able to successfully run 'bundle update'
Postgres 9.4:
gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/Versions/9.4/bin/pg_config
sudo su
then
ARCHFLAGS="-arch x86_64" gem install pg -v '0.18'
worked on 10.10.2
If after trying everything here it still won't install, try opening Xcode and accepting the license agreement.
I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error:
$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/u/.rvm/rubies/ruby-1.9.2-p0/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
--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=/home/u/.rvm/rubies/ruby-1.9.2-p0/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 /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0 for inspection.
Results logged to /home/u/.rvm/gems/ruby-1.9.2-p0/gems/pg-0.11.0/ext/gem_make.out
How do I solve this problem?
It looks like in Ubuntu that header is part of the libpq-dev package (at least in the following Ubuntu versions:
11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04 (Precise Pangolin), 14.04 (Trusty Tahr) and 18.04 (Bionic Beaver)):
...
/usr/include/postgresql/libpq-fe.h
...
So try installing libpq-dev or its equivalent for your OS:
For Ubuntu/Debian systems: sudo apt-get install libpq-dev
On Red Hat Linux (RHEL) systems: yum install postgresql-devel
For Mac Homebrew: brew install postgresql
For Mac MacPorts PostgreSQL: gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
For OpenSuse: zypper in postgresql-devel
For ArchLinux: pacman -S postgresql-libs
On macOS (previously Mac OS X and OS X), use Homebrew to install the proper headers:
brew install postgresql
and then running
gem install pg
should work.
Alternatively, instead of installing the whole postgresql, you can brew install libpq and export the correct PATH and PKG_CONFIG_PATH as explained in the 'Caveats' section
I had also tried doing gem install libpq-dev, but I received this error:
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
However I found that installing with sudo apt-get (which I try to avoid using with Ruby on Rails) worked, i.e.
sudo apt-get install libpq-dev
# or
apt-get install postgres-server-dev-{pg.version}
# for postgresql 9.4 on Ubuntu 14.04
then I was able to do
gem install pg
without issues.
I could solve this in another way. I didn't find the library on my system. Thus I installed it using an app from PostgreSQL main website. In my case (OS X) I found the file under /Library/PostgreSQL/9.1/include/ once the installation was over. You may also have the file somewhere else depending on your system if you already have PostgreSQL installed.
Thanks to this link on how to add an additional path for gem installation, I could point the gem to the lib with this command:
export CONFIGURE_ARGS="with-pg-include=/Library/PostgreSQL/9.1/include/"
gem install pg
After that, it works, because it now knows where to find the missing library. Just replace the path with the right location for your libpq-fe.h
Can't find the libpq-fe.h header
i had success on CentOS 7.0.1406 running the following commands:
~ % psql --version # => psql (PostgreSQL) 9.4.1
yum install libpqxx-devel
gem install pg -- --with-pg-config=/usr/pgsql-9.4/bin/pg_config
Alternatively, you can configure bundler to always install pg with these options (helpful for running bundler in deploy environments),
bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config
For CentOS 6.4,
yum install postgresql-devel
gem install pg
worked well!
Just for the record:
Ruby on Rails 4 application in OS X with PostgresApp (in this case 0.17.1 version needed - kind of an old project):
gem install pg -v '0.17.1' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
It is only issue of missing libpq-fe.h
On ubuntu we just need to run:
sudo apt-get install libpq-dev
Above command will install a NEW package libpq-dev and after that you can again execute bundle install to resume your bundle installation.
On Mac OS X run like this:
gem install pg -- --with-pg-config=***/path/to/pg_config***
***/path/to/pg_config*** is path to pg_config
In my case it was package postgresql-server-dev-8.4 (I am on Ubuntu 11.04 (Natty Narwhal), 64 bits).
For MacOS without installing PostgreSQL server:
brew install libpq
gem install pg -- --with-pg-config="/usr/local/Cellar/libpq/9.6.6/bin/pg_config"
The right answer for Mac users with Postgres.app is to build against the libpq provided with that package. For example, with the 9.4 release (current as of this writing), all you need is:
export CONFIGURE_ARGS="with-pg-include=/Applications/Postgres.app/Contents/Versions/9.4/include"
gem install pg
This will keep your pg gem in sync with exactly the version of PostgreSQL you have installed. Installing something from Homebrew is a waste in this case.
I had the same issue on Amazon Linux. I could find the header libpq-fe.h, but somehow it didn't work.
It came from the different versions of the packages that were installed through the different users on the machine. PostgreSQL 9.2 and PostgreSQL 9.3 were installed. So, make sure of your PostgreSQL version before including the libraries.
For me, the magic command line was:
sudo yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel
Source: An almost idiot's guide to install PostgreSQL 9.3, PostGIS 2.1 and pgRouting with Yum
My solution for Fedora 30:
sudo dnf install /usr/include/libpq-fe.h
A more general answer for any Debian-based distribution (which includes Ubuntu) is the following. First, install the apt-file package running as root:
apt-get install apt-file
This allows you to search for packages containing a file. Then, update its database using
apt-file update
(this can be run as normal user). Then, look for the missing header using:
apt-file search libpq-fe.h
On my machine, this gives:
libpq-dev: /usr/include/postgresql/libpq-fe.h
postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h
There you go !
On Ubuntu, install the "libpq-dev" to get rid of this issue.
sudo apt-get install libpq-dev
On Fedora 32, I managed to solve this same issue by installing libpq5-devel specifically.
If you install postgresql from the official repository, you will have several versions that won't fix the problem, so it's really a matter of trying out which one it needs.
I had the same problem on Mac OS, but I installed the PostgreSQL gem easily by using the following in a terminal:
ARCHFLAGS="-arch x86_64" gem install pg
(I installed PostgreSQL first with brew install postgresql.)
I found this answer, and it was the only one that worked for me (Mac OS) - after researching for about two days:
$ sudo su
$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions. This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...
See Stack Overflow question Can't find the PostgreSQL client library (libpq).
I recently upgraded to Mac OS X v10.10 (Yosemite) and was having difficulty building the pg gem.
The error reported was the typical:
Using config values from /usr/local/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***
My solution was to gem uninstall pg and then bundle update pg to replace the gem with the latest. I did run brew update; brew upgrade after the Yosemite install to get the latest versions of packages I had installed previously.
On a Mac, I solved it using this code:
gem install pg -v '0.18.4' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
I had this issue with Postgresql 9.6. I was able to fix it by doing:
brew upgrade postgresql#9.6
brew link postgresql#9.6 --force
gem install pg
I am running Postgres.app on a Mac and I had to
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
first. Then
bundle install
worked for me.
I encountered the same error with postgres installed through asdf. The pg-config solutions didn't work for me. Instead I had to locate the postgres include folder which contains the file and run the command with the --with-pg-include flag
gem install pg -- --with-pg-include=/<path>/.asdf/installs/postgres/<version>/include
On CentOS,I installed libpq-dev package using below command
yum install postgresql-devel
Executing gem install pg returned the same error as "No pg_config... trying anyway. If building fails, please try again with --with-pg-config=/path/to/pg_config".
Installing the gem as below solved my problem
gem install pg -- --with-pg-config=/usr/pgsql-x.x/bin/pg_config
On Ubuntu 20.04, I already had libpq5:amd64 version 13.2-1.pgdg20.04+1. Now when I tried to install libpq-dev from apt repository, I was receiving
The following packages have unmet dependencies:
libpq-dev : Depends: libpq5 (= 12.6-0ubuntu0.20.04.1) but 13.2-1.pgdg20.04+1 is to be installed
I grabbed the deb from http://ftp.us.debian.org/debian/pool/main/p/postgresql-13/libpq-dev_13.2-1_amd64.deb and did the following:
mkdir -p /tmp/libpq-dev
dpkg-deb -R libpq-dev_13.2-1_amd64.deb /tmp/libpq-dev
sed -i 's|= 13.2-1|= 13.2-1.pgdg20.04+1|' /tmp/libpq-dev/DEBIAN/control
dpkg-deb -b /tmp/libpq-dev /tmp/libpq-dev-new.deb
sudo dpkg -i /tmp/libpq-dev-new.deb
I have been using the gem happily after that. No additional installs or anything.
For alpine, please use below to fix the error
apk add --no-cache postgresql-dev
On debian bullseye, none of the existing answers solved the issue for me.
In case it helps someone with the same configuration as mine:
Use PostgreSQL's apt repository: https://wiki.postgresql.org/wiki/Apt
sudo apt-get update && sudo apt-get dist-upgrade (upgrade PostgreSQL from v13 to v14)
sudo apt-get install libpq-dev
gem install pg or bundle install
On FreeBSD (9.1) the necessary package is /usr/ports/database/postgresql-server* which when installed will also install the required header file that makes the gem install of "pg" fail. This answer here helped me find the solution but the difference in package names required a bit of searching.
Hopefully this helps someone avoid a bit of head scratching when searching for the "-dev" package on a FreeBSD system!
On Debian 7.0, 64-bit (Wheezy), just run:
sudo apt-get install libpq-dev
After you successfully installed libpq-dev, run:
bundle install