Question

"gem install pg" not working

Posted October 17, 2013 47.9k 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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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

found a solution:

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

then 'gem install pg should work'
Submit an Answer