"gem install pg" not working

October 17, 2013 15.7k views
Hello, I'm trying to install the ruby pg gem and I had this exact problem on my mac because of 64 bit architecture. The solution was something like "sudo env ARCHFLAGS="-arch x86_64" gem install pg" (http://stackoverflow.com/questions/10344821/gem-install-pg-doesnt-work-on-osx-lion). I suspect it is the same problem since my server is running Ubuntu 12.04 x64. The command "gem install pg" doesn't work and gives me the following error:
Fetching: pg-0.17.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
	ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
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.
As a warning, I am a straight up noob at this stuff. Any thoughts?
3 Answers
On Ubuntu $ sudo apt-get install postgresql-client libpq5 libpq-dev $ sudo gem install pg

After a day fighting, I found out through the mkmf.log that the command "ld -lgmp" was failing. So I installed the libgmp-dev package and now it works.

  • Thank you so much. This fixed my problems. Strangely, this is the first time I need the package. Every earlier (about 20 times) installation worked fine.

found a solution:

use these commands http://stackoverflow.com/questions/4564117/sudo-gem-install-pg-wont-work

then 'gem install pg should work'
Have another answer? Share your knowledge.