I've reviewed all the posts on SO with similar errors installing the Postgres pg gem.
My issue is unique: I can successfully add Postgres to my Sinatra Ruby project via the Gemfile and bundle install -- however when building the Docker image it fails installing pg with the following error:
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: /usr/local/bundle/gems/pg-0.19.0/ext
/usr/local/bin/ruby -r ./siteconf20170113-7-ottv1k.rb 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 ***
I've tried everything suggested in similar answers:
pg_config and libpq-fe.hAs I'm not too familiar with Docker, is there something I'm missing about installing a db with Docker?
Any help much much appreciated in advance. Thank you.
You got this error because of missing libpq-dev package.
Here is the minimal ubuntu-based Dockerfile for installing pg gem:
FROM ruby:2.6.6-slim-buster
RUN apt update && apt install -y \
build-essential libpq-dev \
&& rm -rf /var/lib/apt/lists/*
RUN gem install pg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With