Skip to content

Instantly share code, notes, and snippets.

@prdanelli
Last active February 1, 2022 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prdanelli/a0dd4684022459e0d344bd0a4d6b4ec7 to your computer and use it in GitHub Desktop.
Save prdanelli/a0dd4684022459e0d344bd0a4d6b4ec7 to your computer and use it in GitHub Desktop.
Install PG Gem without installing Postgres locally

Install PG Gem without installing Postgres locally

The Problem

Installing the ruby PG gem requires Postgres to be instaled locally to install the gem, which is annoying and unnecessary if you're building inside of docker.

An error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.2.3' --source 'https://rubygems.org/'` succeeds before bundling.

The Solution

The Original Article.

sudo apt update
sudo apt install libpq-dev

Then you can install the gem:

gem install pg -- --with-opt-dir="/usr/local/opt/libpq"

Issues:

The following packages have unmet dependencies.
 libpq-dev : Depends: libpq5 (= 12.7-0ubuntu0.20.10.1) but 13.3-1.pgdg20.10+1 is to be installed
E: Unable to correct problems, you have held broken packages.

Any newer version of libpq5 can cause this error. In my case it was libpq5=13.1-1.pgdg20.10+1.

sudo apt install libpq5=12.7-0ubuntu0.20.10.1

and then install liqpq-dev again

sudo apt install libpq-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment