Monorepo , React +Rails api, PG Issue on Deployment: Can't find the 'libpq-fe.h header

It seems that there is a specific gem that is not being installed during deployment “Can’t find the 'libpq-fe.h header” . Please see screenshot attached.

What’s odd is that all of my other gems install successfully except this one. The specific libpq gem does not fail locally either. Any thoughts on this?

Hi there, @Shariffintech :wave:

Thanks so much for reaching out, and welcome to the Netlify Forums!

Can you please share the URL of the site that is impacted, as well as the a full copy of the deploy log? A full copy is easier to work with and debug versus a screenshot.

:crossed_fingers:t5:Thank you for getting back to me Hilary!

Please see the full deploy log below:

9:07:31 AM: Build ready to start

9:07:36 AM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)

9:07:36 AM: build-image tag: v4.10.1

9:07:36 AM: buildbot version: 37262c48b1f3cfa88c6caed707d29b19aef6a5a7

9:07:36 AM: Building without cache

9:07:36 AM: Starting to prepare the repo for build

9:07:36 AM: No cached dependencies found. Cloning fresh repo

9:07:36 AM: git clone https://github.com/Shariffintech/abena-dms

9:07:45 AM: Preparing Git Reference refs/heads/main

9:07:45 AM: Parsing package.json dependencies

9:07:46 AM: Different build dir detected, going to use the one specified in the Netlify configuration file: ‘backend/api’ versus ‘backend/api/’ in the Netlify UI

9:07:46 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: ‘backend/api’ versus ‘build’ in the Netlify UI

9:07:46 AM: Starting build script

9:07:46 AM: Installing dependencies

9:07:46 AM: Python version set to 2.7

9:07:46 AM: Downloading and installing node v16.17.0…

9:07:47 AM: Downloading https://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-x64.tar.xz

9:07:47 AM: Computing checksum with sha256sum

9:07:47 AM: Checksums matched!

9:07:49 AM: Now using node v16.17.0 (npm v8.15.0)

9:07:49 AM: Started restoring cached build plugins

9:07:49 AM: Finished restoring cached build plugins

9:07:49 AM: Required ruby-2.6.8 is not installed.

9:07:49 AM: To install do: ‘rvm install “ruby-2.6.8”’

9:07:49 AM: Attempting ruby version ruby-2.6.8, read from .ruby-version file

9:07:50 AM: Required ruby-2.6.8 is not installed - installing.

9:07:50 AM: Searching for binary rubies, this might take some time.

9:07:51 AM: Found remote file https://rubies.travis-ci.org/ubuntu/20.04/x86_64/ruby-2.6.8.tar.bz2

9:07:51 AM: Checking requirements for ubuntu.

9:07:51 AM: Requirements installation successful.

9:07:51 AM: ruby-2.6.8 - #configure

9:07:51 AM: ruby-2.6.8 - #download

9:07:53 AM: No checksum for downloaded archive, recording checksum in user configuration.

9:07:53 AM: ruby-2.6.8 - #validate archive

9:07:57 AM: ruby-2.6.8 - #extract

9:07:59 AM: ruby-2.6.8 - #validate binary

9:07:59 AM: ruby-2.6.8 - #setup

9:07:59 AM: ruby-2.6.8 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.6.8@global

9:07:59 AM: ruby-2.6.8 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems…

9:08:00 AM: ruby-2.6.8 - #generating global wrappers…

9:08:00 AM: ruby-2.6.8 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.6.8

9:08:00 AM: ruby-2.6.8 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list

9:08:00 AM: ruby-2.6.8 - #generating default wrappers…

9:08:00 AM: Using /opt/buildhome/.rvm/gems/ruby-2.6.8

9:08:01 AM: Using ruby version 2.6.8

9:08:01 AM: Using bundler version 2.2.22 from Gemfile.lock

9:08:02 AM: Successfully installed bundler-2.2.22

9:08:02 AM: 1 gem installed

9:08:02 AM: Using PHP version 8.0

9:08:02 AM: Started restoring cached ruby gems

9:08:02 AM: Finished restoring cached ruby gems

9:08:02 AM: Installing gem bundle

9:08:02 AM: [DEPRECATED] The --path flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use bundle config set --local path '/opt/build/cache/bundle', and stop using this flag

9:08:02 AM: [DEPRECATED] The --binstubs option will be removed in favor of bundle binstubs --all

9:08:03 AM: Fetching gem metadata from https://rubygems.org/

9:08:04 AM: Fetching gem metadata from https://rubygems.org/

9:08:04 AM: Fetching rake 13.0.6

9:08:04 AM: Installing rake 13.0.6

9:08:04 AM: Fetching minitest 5.16.2

9:08:04 AM: Fetching crass 1.0.6

9:08:04 AM: Fetching nio4r 2.5.8

9:08:04 AM: Fetching websocket-extensions 0.1.5

9:08:04 AM: Fetching mini_mime 1.1.2

9:08:04 AM: Fetching jsonapi-renderer 0.2.2

9:08:04 AM: Using bundler 2.2.22

9:08:04 AM: Fetching method_source 1.0.0

9:08:04 AM: Fetching thor 1.2.1

9:08:04 AM: Fetching rb-fsevent 0.11.1

9:08:04 AM: Fetching concurrent-ruby 1.1.10

9:08:04 AM: Fetching zeitwerk 2.6.0

9:08:04 AM: Fetching racc 1.6.0

9:08:04 AM: Fetching rack 2.2.4

9:08:04 AM: Fetching marcel 1.0.2

9:08:04 AM: Fetching bcrypt 3.1.18

9:08:04 AM: Fetching coderay 1.1.3

9:08:04 AM: Fetching byebug 11.1.3

9:08:04 AM: Fetching orm_adapter 0.5.0

9:08:04 AM: Fetching ffi 1.15.5

9:08:04 AM: Fetching hashie 5.0.0

9:08:04 AM: Fetching spring 1.7.2

9:08:04 AM: Fetching builder 3.2.4

9:08:04 AM: Fetching erubi 1.10.0

9:08:04 AM: Fetching execjs 2.8.1

9:08:04 AM: Fetching pg 1.4.1

9:08:04 AM: Fetching rake_tasks 5.1.1

9:08:04 AM: Fetching tilt 2.0.10

9:08:04 AM: Installing jsonapi-renderer 0.2.2

9:08:04 AM: Installing websocket-extensions 0.1.5

9:08:04 AM: Installing crass 1.0.6

9:08:04 AM: Installing method_source 1.0.0

9:08:04 AM: Installing orm_adapter 0.5.0

9:08:04 AM: Installing erubi 1.10.0

9:08:04 AM: Installing mini_mime 1.1.2

9:08:04 AM: Installing builder 3.2.4

9:08:04 AM: Installing execjs 2.8.1

9:08:04 AM: Installing tilt 2.0.10

9:08:04 AM: Installing zeitwerk 2.6.0

9:08:04 AM: Installing rake_tasks 5.1.1

9:08:04 AM: Installing rb-fsevent 0.11.1

9:08:04 AM: Installing spring 1.7.2

9:08:04 AM: Installing marcel 1.0.2

9:08:05 AM: Installing hashie 5.0.0

9:08:05 AM: Installing bcrypt 3.1.18 with native extensions

9:08:05 AM: Installing thor 1.2.1

9:08:05 AM: Installing racc 1.6.0 with native extensions

9:08:05 AM: Installing minitest 5.16.2

9:08:05 AM: Installing byebug 11.1.3 with native extensions

9:08:05 AM: Installing coderay 1.1.3

9:08:05 AM: Installing rack 2.2.4

9:08:05 AM: Installing nio4r 2.5.8 with native extensions

9:08:05 AM: Fetching websocket-driver 0.7.5

9:08:05 AM: Installing pg 1.4.1 with native extensions

9:08:05 AM: Installing websocket-driver 0.7.5 with native extensions

9:08:05 AM: Installing concurrent-ruby 1.1.10

9:08:05 AM: Fetching mail 2.7.1

9:08:05 AM: Fetching uglifier 4.2.0

9:08:05 AM: Installing ffi 1.15.5 with native extensions

9:08:05 AM: Installing mail 2.7.1

9:08:05 AM: Installing uglifier 4.2.0

9:08:16 AM: Fetching rack-test 2.0.2

9:08:16 AM: Fetching pry 0.13.1

9:08:16 AM: Fetching better_errors 2.9.1

9:08:16 AM: Fetching warden 1.2.9

9:08:16 AM: Fetching sprockets 3.7.2

9:08:16 AM: Fetching omniauth 1.9.1

9:08:16 AM: Fetching tzinfo 2.0.5

9:08:16 AM: Fetching i18n 1.12.0

9:08:16 AM: Fetching puma 5.6.4

9:08:16 AM: Fetching nokogiri 1.13.7 (x86_64-linux)

9:08:16 AM: Fetching rb-inotify 0.10.1

9:08:16 AM: Installing warden 1.2.9

9:08:16 AM: Installing rack-test 2.0.2

9:08:16 AM: Installing better_errors 2.9.1

9:08:16 AM: Installing omniauth 1.9.1

9:08:16 AM: Installing rb-inotify 0.10.1

9:08:16 AM: Installing i18n 1.12.0

9:08:16 AM: Installing sprockets 3.7.2

9:08:16 AM: Installing tzinfo 2.0.5

9:08:16 AM: Installing pry 0.13.1

9:08:16 AM: Installing puma 5.6.4 with native extensions

9:08:16 AM: Fetching listen 3.7.1

9:08:16 AM: Fetching sass-listen 4.0.0

9:08:16 AM: Installing listen 3.7.1

9:08:16 AM: Installing sass-listen 4.0.0

9:08:16 AM: Fetching activesupport 6.1.6.1

9:08:16 AM: Fetching sass 3.7.4

9:08:16 AM: Installing activesupport 6.1.6.1

9:08:16 AM: Installing sass 3.7.4

9:08:16 AM: Installing nokogiri 1.13.7 (x86_64-linux)

9:08:19 AM: Fetching activemodel 6.1.6.1

9:08:19 AM: Fetching case_transform 0.2

9:08:19 AM: Fetching globalid 1.0.0

9:08:19 AM: Fetching rails-dom-testing 2.0.3

9:08:19 AM: Fetching loofah 2.18.0

9:08:19 AM: Fetching pry-byebug 3.9.0

9:08:19 AM: Fetching pry-rails 0.3.9

9:08:19 AM: Installing globalid 1.0.0

9:08:19 AM: Installing case_transform 0.2

9:08:19 AM: Installing pry-byebug 3.9.0

9:08:19 AM: Installing rails-dom-testing 2.0.3

9:08:19 AM: Installing pry-rails 0.3.9

9:08:19 AM: Installing loofah 2.18.0

9:08:19 AM: Installing activemodel 6.1.6.1

9:08:19 AM: Fetching activejob 6.1.6.1

9:08:19 AM: Fetching rails-html-sanitizer 1.4.3

9:08:19 AM: Installing activejob 6.1.6.1

9:08:19 AM: Installing rails-html-sanitizer 1.4.3

9:08:19 AM: Fetching activerecord 6.1.6.1

9:08:19 AM: Fetching actionview 6.1.6.1

9:08:19 AM: Installing activerecord 6.1.6.1

9:08:19 AM: Installing actionview 6.1.6.1

9:08:19 AM: Fetching actionpack 6.1.6.1

9:08:19 AM: Installing actionpack 6.1.6.1

9:08:19 AM: Fetching active_model_serializers 0.10.13

9:08:19 AM: Fetching actioncable 6.1.6.1

9:08:19 AM: Fetching sprockets-rails 3.4.2

9:08:19 AM: Fetching railties 6.1.6.1

9:08:19 AM: Fetching actionmailer 6.1.6.1

9:08:19 AM: Fetching activestorage 6.1.6.1

9:08:19 AM: Installing sprockets-rails 3.4.2

9:08:19 AM: Installing actionmailer 6.1.6.1

9:08:19 AM: Installing actioncable 6.1.6.1

9:08:19 AM: Installing activestorage 6.1.6.1

9:08:19 AM: Installing active_model_serializers 0.10.13

9:08:20 AM: Installing railties 6.1.6.1

9:08:20 AM: Fetching actionmailbox 6.1.6.1

9:08:20 AM: Fetching actiontext 6.1.6.1

9:08:20 AM: Installing actiontext 6.1.6.1

9:08:20 AM: Installing actionmailbox 6.1.6.1

9:08:20 AM: Fetching jquery-rails 4.5.0

9:08:20 AM: Fetching sass-rails 5.1.0

9:08:20 AM: Fetching responders 3.0.1

9:08:20 AM: Fetching rails 6.1.6.1

9:08:20 AM: Creating deploy upload records

9:08:20 AM: Installing responders 3.0.1

9:08:20 AM: Installing sass-rails 5.1.0

9:08:20 AM: Installing rails 6.1.6.1

9:08:20 AM: Fetching devise 4.8.1

9:08:20 AM: Installing jquery-rails 4.5.0

9:08:20 AM: Installing devise 4.8.1

9:08:20 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 1 (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)

9:08:20 AM: Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

9:08:20 AM: current directory: /opt/build/cache/bundle/ruby/2.6.0/gems/pg-1.4.1/ext

9:08:20 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.8/bin/ruby -I

9:08:20 AM: /opt/buildhome/.rvm/rubies/ruby-2.6.8/lib/ruby/2.6.0 -r

9:08:20 AM: ./siteconf20220913-3283-47dpo1.rb extconf.rb

9:08:20 AM: Calling libpq with GVL unlocked

9:08:20 AM: checking for pg_config… no

9:08:20 AM: checking for libpq per pkg-config… no

9:08:20 AM: Using libpq from

9:08:20 AM: checking for libpq-fe.h… no

9:08:20 AM: Can’t find the 'libpq-fe.h header

9:08:20 AM: *****************************************************************************

9:08:20 AM: Unable to find PostgreSQL client library.

9:08:20 AM: Please install libpq or postgresql client package like so:

9:08:20 AM: sudo apt install libpq-dev

9:08:20 AM: sudo yum install postgresql-devel

9:08:20 AM: sudo zypper in postgresql-devel

9:08:20 AM: sudo pacman -S postgresql-libs

9:08:20 AM: or try again with:

9:08:20 AM: gem install pg – --with-pg-config=/path/to/pg_config

9:08:20 AM: or set library paths manually with:

9:08:20 AM: gem install pg – --with-pg-include=/path/to/libpq-fe.h/

9:08:20 AM: --with-pg-lib=/path/to/libpq.so/

9:08:20 AM: *** extconf.rb failed ***

9:08:20 AM: Could not create Makefile due to some reason, probably lack of necessary

9:08:20 AM: libraries and/or headers. Check the mkmf.log file for more details. You may

9:08:20 AM: need configuration options.

9:08:20 AM: Provided configuration options:

9:08:20 AM: --with-opt-dir

9:08:20 AM: --without-opt-dir

9:08:20 AM: --with-opt-include

9:08:20 AM: --without-opt-include=${opt-dir}/include

9:08:20 AM: --with-opt-lib

9:08:20 AM: --without-opt-lib=${opt-dir}/lib

9:08:20 AM: --with-make-prog

9:08:20 AM: --without-make-prog

9:08:20 AM: --srcdir=.

9:08:20 AM: --curdir

9:08:20 AM: --ruby=/opt/buildhome/.rvm/rubies/ruby-2.6.8/bin/$(RUBY_BASE_NAME)

9:08:20 AM: --with-pg

9:08:20 AM: --without-pg

9:08:20 AM: --enable-gvl-unlock

9:08:20 AM: --disable-gvl-unlock

9:08:20 AM: --enable-windows-cross

9:08:20 AM: --disable-windows-cross

9:08:20 AM: --with-pg-config

9:08:20 AM: --without-pg-config

9:08:20 AM: --with-pg_config

9:08:20 AM: --without-pg_config

9:08:20 AM: --with-libpq-config

9:08:20 AM: --without-libpq-config

9:08:20 AM: --with-pkg-config

9:08:20 AM: --without-pkg-config

9:08:20 AM: --with-pg-dir

9:08:20 AM: --without-pg-dir

9:08:20 AM: --with-pg-include

9:08:20 AM: --without-pg-include=${pg-dir}/include

9:08:20 AM: --with-pg-lib

9:08:20 AM: --without-pg-lib=${pg-dir}/lib

9:08:20 AM: To see why this extension failed to compile, please check the mkmf.log which can

9:08:20 AM: be found here:

9:08:20 AM: /opt/build/cache/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/pg-1.4.1/mkmf.log

9:08:20 AM: extconf failed, exit code 1

9:08:20 AM: Gem files will remain installed in

9:08:20 AM: /opt/build/cache/bundle/ruby/2.6.0/gems/pg-1.4.1 for inspection.

9:08:20 AM: Results logged to

9:08:20 AM: /opt/build/cache/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0/pg-1.4.1/gem_make.out

9:08:20 AM: An error occurred while installing pg (1.4.1), and Bundler cannot continue.

9:08:20 AM: Make sure that gem install pg -v '1.4.1' --source 'https://rubygems.org/'

9:08:20 AM: succeeds before bundling.

9:08:20 AM: In Gemfile:

9:08:20 AM: pg

9:08:20 AM: Error during gem install

9:08:20 AM: Build was terminated: Build script returned non-zero exit code: 1

9:08:20 AM: Failing build: Failed to build site

9:08:21 AM: Finished processing build request in 45.064251896s

Hey @Shariffintech

There are several threads about libpq in these forums, however most relate to NodeJS, and this thread about Rails doesn’t have an answer.

I found a couple of posts on Stack Overflow suggesting there is a need to install libpq-dev however this isn’t necessarily possible on Netlify.

Hi @coelmay that’s what I found to be true as well. I wanted to see if Netlify can add this package to their environment from their end since they dont allow users to SSH into the server and add it.

I thought this would be an easy fix with Ubuntu but keep running into this wall. Would hate to have to switch to a different service because of it i.e Railway or pay high $ through AWS.

If all you need is to install postgresql to get this working, I believe you can do so using:

2 Likes