---
title: "PostgreSQL gem install fails"
date: "2015-11-03"
category: "ruby"
slug: "postgresql-gem-install-fails"
---

## Symptom

Installing the Ruby gem "pg" or other PostgreSQL-dependent gems on [[determining-platform-version]] fails with an error like:

Can't find the PostgreSQL client library (libpq)
\*\*\* 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.
Provided configuration options:
 --with-opt-dir

## Cause

PostgreSQL libraries are installed in `/usr/pgsql-XX` (where _XX_ is the version number), which is not in the default library search path.

## Solution

Specify the path to `pg_config` when installing the gem. For example, on Sol (PostgreSQL 9.3):

```
gem install pg -v '0.18.3' -- --with-pg-config=/usr/pgsql-9.3/bin/pg_config
```

Adjust the PostgreSQL version number to match your [[determining-platform-version]].
