Can't find the 'libpq-fe.h header when trying to install pg gem
Asked Answered
T

50

986

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?

Thorite answered 18/5, 2011 at 6:11 Comment(1)
can you prove that you have pg installed?Nozicka
W
1552

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
Wiggins answered 18/5, 2011 at 6:11 Comment(23)
didn't work for me on ubuntu 11.04 durrantm@castleLinux2011:~/Dropbox_not_syncd/webs/3/linker$ gem install libpq-dev ERROR: Could not find a valid gem 'libpq-dev' (>= 0) in any repository durrantm@castleLinux2011:~/Dropbox_not_syncd/webs/3/linker$ Bobble
If you then are required to have a javascript library installed... gem install 'execjs' and gem install 'therubyracer'Ulphia
@TravisR: Thanks for the update, I just turned this into a community wiki to make it easier for everyone to keep it up to date.Wiggins
I am using Ubuntu 12.10, I am not able to install pg gem after installing libpq-devUnsegregated
@vedarthk: What does "not able" mean? Perhaps a new question with the install logs would get you the help you need.Wiggins
@muistooshort Yes I have posted the question : https://mcmap.net/q/54429/-not-able-to-install-pg-gem-on-ubuntu-12-10/1277376Unsegregated
Works with Ubuntu 12.04 64 bitWicked
In Mac OS X, get homebrew from brew.sh , then brew install postgres to install PostgresQL and its header files.Excursus
Works like a charm in centOS 6.5Barkeeper
Please revise your answer to include apt-get install postgres-server-dev-{pg.version} Your answer no longer works with postgresql 9.4 on Ubuntu 14.04 See: https://mcmap.net/q/54430/-rails-4-2-0-can-39-t-install-pg-gem-on-ubuntu-14-04Perfectionism
@RyanRauh: Can you submit an edit? I'm not using Ubuntu right now so I'm not really qualified to say much here.Wiggins
I just had a probelm with this because I was confusing g and q. to be clear, the package wanted is libpq-dev with a Q not a GSchoolbag
I tried to do that on Ubuntu 14.04 but it gave me this: " libpq-dev : Depends: libpq5 (= 9.3.4-1) but 9.3.10-0ubuntu0.14.04 is to be installed.Disgrace
But then when I try to install libpq5, it says "libpq5 is already the newest version. Same for PostgreSQL."Disgrace
PostgreSQL version is: psql --version: psql (PostgreSQL) 9.3.10. PostgreSQL 9.3.10 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit.Disgrace
The following packages have unmet dependencies: postgresql-server-dev-9.3 : Depends: libpq-dev (>= 9.3~) but it is not going to be installed E: Unable to correct problems, you have held broken packages.Disgrace
@MichaelLafayette I don't have Ubuntu set up anywhere right now so I don't know what the problem could be.Wiggins
While I executed the command : sudo apt-get install libpq-dev, I get a response - "Unable to locate package". So I execute sudo apt-get update, then executed "sudo apt-get install libpq-dev". Finally it successfully installed.Blench
Why do gem designers rely on implicit, undocumented, globally installed dependencies, and make no attempt to check for their existence before installing the gem?Stria
@AndyRay But they are checking for dependencies, that's what "checking for pg_config" and "checking for libpq-fe.h" are about. There's no way to check if the PostgreSQL development stuff is installed without, well, installing some scripts that look for the standard PostgreSQL dev tools (such as pg_config or the header file). Same thing happens when you need anything that isn't packaged inside a gem.Wiggins
Ubuntu/Debian systems solution valid for Raspbian v9.9 on Raspberry Pi devices.Ponce
I tried the same steps but still getting error in Redhat: Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. current directory: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/pg-1.1.4/ext /opt/chef/embedded/bin/ruby -r ./siteconf20190924-18624-nckmb.rb extconf.rb checking for pg_config... yes Using config values from /bin/pg_config checking for libpq-fe.h... *** extconf.rb failed ***Quadratics
This worked for me, I already had installed Postgres, and I just needed to execute sudo apt-get install libpq-dev then bundle install and the error disappeared. ThanksOttie
D
241

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

Decumbent answered 9/12, 2013 at 22:30 Comment(9)
Does this cause any problems if you're also using Postgres.app?Besse
@Besse I use Postgres.app to run a db instance so having the pg gem just allows you to hook your Rails app up to your local Postgres.app instanceDecumbent
For me after run brew install postgressql i run ARCHFLAGS="-arch x86_64" gem install pg and works fine.Chiliad
Alternatively, just running brew install libpqxx on mac OSX sufficesSimp
@RicardoSaporta libpqxx installs postgresql as dependency, so it is essentially the same as brew install postgresqlReposit
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.Forgetful
This also sorted it for me on Ubuntu 20.04 using Linuxbrew. sudo apt-get install libpq-dev kept failing because of some other dependencyAbsorber
As someone who's just been hired to work with Ruby/Rails for the first time... Are there many more issues like this? Where a build requires a database installation to run? Do Ruby builds keep breaking for random reasons like this?Correlation
@Besse I can confirm this does not cause problems with Postgres.app. I've installed Postgres.app and done 'brew install postgres' on two Macs now, in order to get around the problem of pg not installing due to missing headers. Both times worked great, and allow successful bundle install or gem install pg. No need for specifying --with-pg-config, that was a red herring for me.Brazilin
B
130

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.

Bobble answered 16/1, 2012 at 23:34 Comment(1)
Right, the Ruby pg gem wraps the usual PostgreSQL C libraries that come with the Ubuntu/Debian/... libpq-dev package.Wiggins
R
57

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

Rhinestone answered 12/1, 2012 at 6:52 Comment(7)
David's solution worked for me. I tracked libpq-fe.h to '/Applications/Postgres.app/Contents/Versions/9.3/include' and used the export command with said path, followed by the 'gem install pg' and the gem installed successfully.Nobe
Thanks for this, worked for me, using: export CONFIGURE_ARGS="with-pg-include=/usr/local/Cellar/postgresql/9.3.1/include/"Anecdotist
Using Postgresql 9.3 on CentOS 6 I solved this by symlinking the pg_* scripts into the $PATH like so: ln -s /usr/pgsql-9.3/bin/p* /usr/local/bin. I installed postgres 9.3 like so: yum install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm && yum install postgresql93 postgresql93-contrib postgresql93-server postgresql93-develInspect
you can also write as gem install pg -- with-pg-include=/Library/PostgreSQL/9.1/include/Classified
Better yet, use export CONFIGURE_ARGS="with-pg-config=/path/to/postgres/bin/pg_config". The pg_config executable will be called to get all the required compiler and linker options — you can run it yourself to see them.Fanatical
David's version didn't work for installing an old version of the gem (0.21), but @skozin's instruction did. Thank you!Koweit
this worked perfectly for me on ubuntu 20.04 LTS. Thank you!Iceman
C
33

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
Classified answered 2/3, 2015 at 1:51 Comment(4)
very helpful, thanks. Just to add a note regarding bundle config... you must run this command while logged-in as the user who will be running the subsequent bundle command. The bundler config is stored in ~/.bundle/config, so it will not be found if you run bundle config while logged-in as root, but bundler is being run by (e.g. with capistrano) the 'deploy' user.Ignatzia
bundle config build.pg --with-pg-config=/usr/pgsql-9.4/bin/pg_config solve i for me on Centos 7Devoice
bundle config build.pg --with-pg-config=/usr/pgsql-10/bin/pg_config if you are using postgresql10Fugacity
For postgres 12 and above I had to do yum install libpq5-develMilliken
C
26

For CentOS 6.4,

yum install postgresql-devel
gem install pg

worked well!

Callus answered 10/4, 2013 at 9:13 Comment(1)
Using macports, sudo port install postgresql-devel.Polydeuces
D
19

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
Demerol answered 19/10, 2015 at 16:53 Comment(1)
Works great if you're using the wonderful Postgres.app. For Postgres 10, I used the path /Applications/Postgres.app/Contents/Versions/10/bin/pg_configAngieangil
C
18

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.

Crowboot answered 13/6, 2021 at 19:11 Comment(1)
worked like a charm! sudo apt-get install libpq-dev && cd project-directory && bundle install .Badger
R
16

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

Ragi answered 8/1, 2014 at 9:36 Comment(1)
Upvoted. I installed Postgresql via EnterpriseDB's grapihcal installer. Then I need to find out the pg-config path by sudo find / -name "pg_config", then do gem install pg -- --with-pg-config=/Library/PostgreSQL/9.4/bin/pg_config using the path I have just found out.Wariness
P
14

In my case it was package postgresql-server-dev-8.4 (I am on Ubuntu 11.04 (Natty Narwhal), 64 bits).

Profiterole answered 18/7, 2011 at 18:18 Comment(0)
S
13

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"
Stpeter answered 9/12, 2017 at 10:13 Comment(0)
C
13

My solution for Fedora 30:

sudo dnf install /usr/include/libpq-fe.h
Com answered 19/6, 2019 at 21:26 Comment(3)
I would love to buy you a beer sometime. This is the ONLY thing that worked in Centos 7/8 after hours struggling with itLookthrough
worked for me on fedora 35 . thanks aaron bro. wonder how you figured it out.Galagalactagogue
Worked for me on Red Hat Enterprise Linux release 8.0. ThanksConsider
W
10

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.

Words answered 18/5, 2011 at 6:11 Comment(0)
R
9

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

Riesling answered 30/1, 2015 at 7:47 Comment(1)
After installing libraries... do a clean up: "make distclean", "make clean", "./configure" and start compiling!Schwab
S
8

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 !

Stake answered 29/8, 2013 at 21:16 Comment(4)
"libpq-dev: /usr/include/postgresql/libpq-fe.h" is present whereas "postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.h" is not present ? what am I missing ?Ivory
File contents may have changed. This looks like there was a private copy of libpq-fe.h in the postgres-... package. In any case, the libXXX-dev is the one you're looking for if you want to compile things.Stake
So once found, what is the next step?Hbomb
apt-get install the_package_you_foundStake
P
8

On Ubuntu, install the "libpq-dev" to get rid of this issue.

sudo apt-get install libpq-dev
Pathic answered 12/11, 2017 at 13:34 Comment(1)
If it is not enough, add sudo apt-get install postgresql before libpq-devDaytoday
V
8

On debian bullseye, none of the existing answers solved the issue for me.

In case it helps someone with the same configuration as mine:

  1. Use PostgreSQL's apt repository: https://wiki.postgresql.org/wiki/Apt
  2. sudo apt-get update && sudo apt-get dist-upgrade (upgrade PostgreSQL from v13 to v14)
  3. sudo apt-get install libpq-dev
  4. gem install pg or bundle install
Vanesavanessa answered 27/6, 2022 at 16:32 Comment(0)
H
7

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.

Hypanthium answered 18/1, 2021 at 23:35 Comment(2)
Doesn't let me edit your answer, you missed a letter, it should be libpq5-devel. It helped though, thanks.Signorina
I swear I had noticed that and fixed it but I guess I just thought about it. Thanks for pointing it out.Hypanthium
R
7

Solved on MacOS M1:

brew install libpq

Then I put in my PATH

echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc

And:

gem install pg
Riordan answered 5/11, 2022 at 0:47 Comment(2)
after echo, you need also to source ~/.zshrcCaspar
works great on my new laptop running MacOS Ventura 13.4. yes, close the window and restart the shell in a new window.Undersheriff
H
6

I had this issue with Postgresql 9.6. I was able to fix it by doing:

brew upgrade [email protected]
brew link [email protected] --force
gem install pg
Hanghangar answered 5/1, 2018 at 20:4 Comment(0)
K
5

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.)

Kreitman answered 10/8, 2014 at 19:39 Comment(0)
A
5

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).

Ami answered 20/10, 2014 at 16:21 Comment(1)
Thank you, this was only one that worked for me!Perceptible
D
5

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.

Dumbhead answered 2/11, 2014 at 12:21 Comment(0)
O
5

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.

Osmometer answered 17/2, 2015 at 14:16 Comment(0)
N
5

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
Newsdealer answered 4/2, 2016 at 21:0 Comment(0)
C
5

I solved it by creating symlink on MacOS Ventura

if postgresql already installed;

brew link postgresql@12 --force

This command will give directory path as below

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/opt/homebrew/opt/postgresql@12/bin:$PATH"' >> ~/.zshrc

you need to add zsh or bash_profile to your computer, whichever you are using

Coltish answered 22/2, 2023 at 6:49 Comment(0)
M
4

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
Menstrual answered 5/2, 2019 at 19:57 Comment(1)
Note: /<path>/.asdf/installs/postgres/<version> is returned by asdf where postgresNogas
V
4

I was able to get it working on MacOS Ventura with Apple Silicon using

brew install libpq
brew install postgresql

gem install pg -- --with-pg-config=/opt/homebrew/Cellar/postgresql@14/14.7/bin/pg_config

Check and replace /postgresql@14/14.7/ with your version.

Vitebsk answered 4/4, 2023 at 18:6 Comment(0)
H
3

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
Hypno answered 21/1, 2015 at 9:26 Comment(0)
R
3

The location of libpq-fe.h depends on where your PostgreSQL install is (which depends on how you installed it). Use locate (http://en.wikipedia.org/wiki/Locate_%28Unix%29) to find the libpq-fe.h file on your machine. If it exists, it will be in the include directory of your PostgreSQL install.

$ locate libpq-fe.h
/Library/PostgreSQL/9.1/include/libpq-fe.h

The bin directory, which contains pg_config, will be in the same directory as the include directory. As the error suggests, use the --with-pg-config option to install the gem:

$ gem install pg --with-pg-config="/Library/PostgreSQL/9.1/bin/pg_config"

Note that you may need to run updatedb if you have never used locate or if you haven't updated since installing PostgreSQL.

Rugg answered 26/1, 2015 at 4:57 Comment(1)
Without a -- before the --with-pg-config=... I get an error: ERROR: While executing gem ... (OptionParser::InvalidOption) invalid option: --with-pg-config=/usr/bin/pg_config)Seaward
W
3

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.

Wristlet answered 12/3, 2021 at 14:34 Comment(0)
L
3

For alpine, please use below to fix the error

apk add --no-cache postgresql-dev
Luiseluiza answered 19/10, 2021 at 23:29 Comment(0)
K
2

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!

Kassiekassity answered 6/9, 2013 at 0:27 Comment(0)
A
2

On Debian 7.0, 64-bit (Wheezy), just run:

sudo apt-get install libpq-dev

After you successfully installed libpq-dev, run:

bundle install
Ashanti answered 19/2, 2014 at 3:30 Comment(0)
A
2

Under CentOS 6.5 (Squeeze) I created a file:

$ sudo touch /etc/profile.d/psql.sh

with content:

pathmunge /usr/pgsql-9.3/bin

Note here, you should set your PostgreSQL path with the pg_config file. You can find this with the command:

$ sudo find / -iname pg_config

Save the file:

$ sudo chmod +x /etc/profile.d/ruby.sh

and try to execute your command again.

Note: Anytime you change the Bash configuration - changing the profile.d configuration - you should reload Bash.

Applicator answered 30/7, 2014 at 3:46 Comment(1)
How did you install postgres? I symlinked the pg_* scripts into the path like so: ln -s /usr/pgsql-9.3/bin/p* /usr/local/bin. After that I didn’t need any additional scripts or environment variables.Inspect
M
2

I finally solved this problem, but not using the previously described methods.

Using brew install postgresql, I find out that it had already been installed, but not linked.

  1. Find out where PostgreSQL is installed, and delete it,

  2. Then brew install postgresql again,

  3. brew link postgresql

  4. gem install pg

Museology answered 15/2, 2016 at 8:24 Comment(1)
"brew link --force postgresql" worked for me but befor that i have to run 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profileUnderthecounter
S
1

I solved this installing the 'postgresql-common' package. This package provides the pg_config binary which is most likely what you were missing.

Scheelite answered 7/1, 2013 at 17:19 Comment(0)
T
1

I was having a similar problem, and this fixed it for me:

gem install do_postgres -- --with-pgsql-server-dir=/Applications/Postgres.app/Contents/MacOS --with-pgsql-server-include=/Applications/Postgres.app/Contents/MacOS/include/server

Source:

https://gist.github.com/oisin/6562181

Trimetrogon answered 7/2, 2014 at 2:27 Comment(0)
R
1

Only uninstalling (sudo apt-get purge) libpq-dev and re-installing it worked for me.

Regulus answered 23/3, 2014 at 15:30 Comment(0)
A
1

On OS X 10.9 (Mavericks), I brew-installed postgresql, and I then had to rvm reinstall my Ruby. I am happy now :)

Athenaathenaeum answered 25/8, 2014 at 20:21 Comment(0)
S
1

For AltLinux the package postgresqlx.x-devel (in my case postgresql9.5-devel) must be installed:

apt-get install postgresql9.5-devel
Soredium answered 2/3, 2016 at 7:23 Comment(1)
You can also install specific versions with yum - yum install postgresqlxx-devel e.g yum install postgresql94-develLively
B
1

I just had this on OSX running brew and [email protected].

My fix was this:

CONFIGURE_ARGS="with-pg-include=/usr/local/opt/[email protected]/include/" bundle install
Bunting answered 4/4, 2017 at 21:17 Comment(0)
I
1

For Mac OS X just install https://postgresapp.com/ and follow steps for command line section and ruby

sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp

Then

sudo ARCHFLAGS="-arch x86_64" gem install pg
Inwards answered 24/4, 2018 at 18:0 Comment(1)
I found the same answer here for the top code section above: postgresapp.com/documentation/cli-tools.html under "Configure your $PATH" then all I had to do was open a new terminal and bundle install. I'm on an M1 Mac.Wolfsbane
P
0

On OS X and MacPorts the -devel package for PostgreSQL is not required any more. Installing the pg gem works as follows:

~ > sudo port install postgresql-devel
...
Error: postgresql-devel has been replaced by postgresql91; please install that port instead
~ > gem install pg -v '0.17.1' -- --with-pg-config=/opt/local/lib/postgresql95/bin/pg_config

See also this post.

Pumice answered 29/8, 2015 at 9:39 Comment(1)
port select --set postgresql postgresql96 or any other version you installed to active symlinks including pg_configRecollection
R
0

On Arch Linux you will need to install postgresql-libs:

sudo pacman -Syu postgresql-libs
Radtke answered 21/3, 2017 at 19:23 Comment(0)
W
0

Step 1) Make sure postgress is installed in your system ( If it's already installed and you can run postgress server on your machine move to step (2)

apt-get install postgresql postgresql-contrib (sol - fatal error: libpq-fe.h: No such file or directory)
sudo apt-get install ruby-dev (required to install postgress below)
sudo gem install pg
sudo service postgresql restart

Step 2) Some of the c++ files are trying to access libpq-fe.h directly and cant find. So we need to manually search every such file and replace libpq-fe.h with postgresql/libpq-fe.h

Command for searching all occurrences of libpq-fe.h in all dir and subdir is grep -rnw ./ -e 'libpq-fe.h'

3) Go to All the file listed by command run in step 2 and manually change libpq-fe.h with postgresql/libpq-fe.h.

Watchdog answered 18/5, 2018 at 23:23 Comment(0)
U
0

I have tried all solutions but only works below command

pip install psycopg2-binary
Uralic answered 18/6, 2020 at 4:29 Comment(0)
H
0

Ubuntu 20.04.1 LTS, this seemed to work for me:

sudo apt-get install ruby ruby-dev libpqxx-dev libpq-fe-dev libpq-dev 
sudo gem install pg -- --with-pg-config=/usr/include/postgresql/pg_config --with-pg-include=/usr/include/postgresql/
Hbomb answered 28/8, 2020 at 4:40 Comment(1)
And ls /usr/include/postgresql/libpq-fe.h /usr/include/postgresql/pg_config can be used to check the files are there to start with.Hbomb
S
0

I just had this problem too. I tried many of the answers above and none worked. What finally worked was to check brew was working fine (brew doctor) and to restart the terminal.

Then the error as gone.

Stoughton answered 4/1 at 22:23 Comment(0)
C
-2

I fixed the same error by doing a Ruby reinstall via rvm:

rvm reinstall 1.9.3
Cannady answered 29/7, 2012 at 22:24 Comment(1)
it helped to recover back to initial ruby distribution from rvm but not fixing the problem.Burnham

© 2022 - 2024 — McMap. All rights reserved.