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.)
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 on Ubuntu 16.04 ,
in gemfile I have gem "rmagick" and when I bundle it says
An error occurred while installing rmagick (2.16.0), and Bundler cannot
continue.
Make sure that `gem install rmagick -v '2.16.0'` succeeds before bundling.
as suggested above when I try gem install rmagick -v '2.16.0' it says
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
current directory: /home/faisal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rmagick-2.16.0/ext/RMagick
/home/faisal/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20160926-26223-16sn0dg.rb extconf.rb
checking for gcc... yes
checking for Magick-config... no
checking for pkg-config... yes
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
checking for outdated ImageMagick version (<= 6.4.9)... *** 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/faisal/.rbenv/versions/2.3.1/bin/$(RUBY_BASE_NAME)
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/home/faisal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/rmagick-2.16.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/faisal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rmagick-2.16.0 for inspection.
Results logged to /home/faisal/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-linux/2.3.0-static/rmagick-2.16.0/gem_make.out
I have tried dozen of different ways provided in different questions but none of the work.
In MacOS, you can do this:
brew unlink imagemagick
brew install imagemagick#6 && brew link imagemagick#6 --force
Try this, You need to run the following commands for ubuntu
sudo apt-get install libmagick++-dev
sudo apt-get install imagemagick
Then try to install
gem install rmagick
On Ubuntu you should first install this
sudo apt-get install libmagickwand-dev
Then install gem install rmagick
On mac/osx, make sure you brew install imagemagick#6 (NOT 7)
On Mac High Sierra - 10.13.4 - https://www.imagemagick.org/script/download.php
sudo port install ImageMagick
sudo gem install rmagick
the only thing that worked for me was
brew unlink pkgconfig
bundle install
brew link pkgconfig
On Fedora (when I installed Redmine) that worked for me:
sudo dnf install ImageMagick-devel
bundle install
You are missing dependencies from Imagemagick which are required for rmagick gem to work
sudo apt-get update
sudo apt-get install imagemagick
Once done, bundle should execute successfully and install the gems.
try this
$ sudo apt-get install libmagick++-dev
and then
bundle install
and install Imagemagick
$ sudo apt-get install imagemagick
Then, install the rmagick gem :
$ sudo gem install rmagick
Type in the following commands on the console -
sudo apt-get install libmagick9-dev
sudo apt-get install graphicsmagick-libmagick-dev-compat
sudo apt-get install libmagickwand-dev
sudo apt-get install libmagickcore-dev
sudo apt-get install libmagick++-dev
Let me know if it solves the issue
On Mac OSX 10.12.3, I have also tried many methods to install rmagick and finally I solved my problem.
brew doctor says
............
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run brew link on these:
imagemagick
Warning: Some keg-only formula are linked into the Cellar.
Linking a keg-only formula, such as gettext, into the cellar with
brew link <formula> will cause other formulae to detect them during
the ./configure step. This may cause problems when compiling those
other formulae.
Binaries provided by keg-only formulae may override system binaries
with other strange results.
You may wish to brew unlink these brews:
imagemagick#6
I did
>brew unlink imagemagick#6
Unlinking /usr/local/Cellar/imagemagick#6/6.9.7-9... 60 symlinks removed
>brew link imagemagick
Linking /usr/local/Cellar/imagemagick/6.9.7-3... 75 symlinks created
then
>gem install rmagick
works for me
My advice: Try to install correct version of imagemagick and listen brew doctors advice.
A little late to the game but the following worked for me on Ubuntu 16.04:
Probably overkill a bit but first you'll want to enable all deb-src lines in your sources.list:
sudo vi /etc/apt/sources.list
Then do an apt update:
sudo apt update
Now you should be able to install all the required packages:
sudo apt install libfreetype6-dev libfontconfig1-dev libpng-dev libwmf-dev libpango1.0-dev librsvg2-dev libmagickcore-dev libmagickwand-dev imagemagick
(personally I installed libmagickcore-dev, libmagickwand-dev, imagemagick one at a time during my debugging but you should be able to install them all at once)
Hope this helps
For Centos 6 for the and above
yum install ImageMagick-devel
bundle install
I have tried following this answer to get the gem to work, but it wont. I have my projects set up such that individuals projects have there own gems instead of all themes gems living in global space, and then I use binstubs to allow me to do things like bin/rails.
So all gems are installed to .bundle/gems/ for each project. the one that always gives me the toughest problems is posgresql. Lets go through the steps.
So I run:
bundle
It explodes stating:
Gem::Installer::ExtensionBuildError: 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
--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
Gem files will remain installed in /Users/Adam/Documents/Rails-Projects/AisisPlatform/.bundle/gems/gems/pg-0.18.1 for inspection.
Results logged to /Users/Adam/Documents/Rails-Projects/AisisPlatform/.bundle/gems/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.
So then, because I have the home brew version installed at 9.4.0 and the posgresql.app installed I then did:
bundle config build.pg --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
Followed by, because I use 18.1
gem install pg -v '0.18.1'
And I got:
Building native extensions. This could take a while...
Successfully installed pg-0.18.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.18.1
Done installing documentation for pg after 2 seconds
1 gem installed
From there I tried bundle Well we are back to square one because even though the gem installed - I get the EXACT same error.
Is this because I am installing the pg gem globally and not locally? How can I fix this? This one project, every time I have to do a rm -rf .bundle/gems Causes this exact issue over and over again.
I should point out I get the same error even if I use the home brew psql pg_config Do all the steps above, just with home brew version, same results.
At the end of the day it was:
ARCHFLAGS="-arch x86_64" bundle install
that worked for me.
reason being:
by default it tries to compile a universal binary, which apparently
fails... so that environment variable makes it only compile the x86
version which is all you need
you can add this line to your ~/.profile or similar: export
ARCHFLAGS="-arch x86_64"
For further reading see: This README for OSX
Make sure Postgres is installed on your computer first
for Ubuntu systems: sudo apt-get install libpq-dev
on RHEL systems: yum install postgresql-devel
for Mac: brew install postgresql
Then run bundle install
I used these commnads of this link
rails 4.2.0: can't install pg gem on ubuntu 14.04
You need install the postgreSQL dev package with header of PostgreSQL
sudo apt-get install libpq-dev
You may also try
sudo apt-get install postgresql-client
sudo apt-get install postgresql postgresql-contrib
Try env ARCHFLAGS="-arch x86_64" gem install pg
Try install postgresql-devel package:
yum -y install postgresql-devel
Notice that the above command wont't ask for permission because of the -y
Confirming Antarr Byrd's answer,
sudo env ARCHFLAGS='-arch x86_64' gem install pg
worked for me.
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
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