By using AWS re:Post, you agree to the Terms of Use

Set up the pg gem - postgresql in development


I'm using Cloud9 on AWS in development and EB for deployment.
Found a lot of old stuff, but having problem to install pg gem.

  1. started with codestar, using ruby on rails app
  2. for now with elastic beanstalk
  3. using IDE Cloud9
  4. added RDS Postgresql for the EB
  5. installed all gems needed, except the pg gem
  • postgresql set in database config for dev and production

  • postgresql93-devel added in the packages.conf

  • tried to add libpq-dev - NOT WORKING (?)

sudo yum install libpq-dev
  • this worked (not sure if this is correct)
sudo yum install postgresql-libs

Still error when installing the gem:

Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

_current directory: /usr/local/rvm/rubies/ruby-2.4.1/lib/ruby/gems/2.4.0/gems/pg-0.21.0/ext_  

/usr/local/rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20171207-7455-1v09v4h.rb extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
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.

Any new ideas how to setup Postgresql with Cloud9 on AWS?

Edited by: mikesk on Dec 7, 2017 2:50 AM

asked 5 years ago893 views
4 Answers

I just ran into this myself, it turns out the package you need is called postgresql-devel on RHEL systems. Try:

sudo yum install postgresql-devel

I agree this should work out of the box. Until we are actually able to set our own base images, or AWS fixes this, though, that should suffice.

answered 5 years ago

As of February 27, 2018, the above solution is not working on Amazon Linux Cloud9. Not sure whether Amazon updated its AMI so that it no longer functions or what.

The pg_config file in /usr/bin references postgresql-9.6, but all of the components necessary to compile the pg gem for pg-9.6 are not installed when booting up the AMI for the first time. What got it working for me was the following:

sudo yum install postgresql96 postgresql96-server postgresql96-libs postgresql96-contrib postgresql96-devel
answered 5 years ago

Thanks very much for posting the instructions. I'd like to ask if anyone knows how to start the postgresql service after installing postgresql on AWS Cloud 9.

I have tried to run sudo service postgresql start without much success.

Similarly, I've also tried to run the following without much success

systemctl enable postgresql-9.6.service
systemctl start postgresql-9.6.service

Any assistance would be much appreciated!

answered 4 years ago

You can follow the instructions on this article:

sudo yum install postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs

sudo service postgresql initdb

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions