Installing the Postgresql Gem with 'Gem Pq' Fails with Error: Failed to Build Gem Native Extension

How to install PostgreSQL: ERROR: Failed to build gem native extension

You're missing the Postgres source code and it's needed to compile the pg gem.

  1. Install brew with

     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  2. Install PostgreSQL server using

     brew install postgresql

But it also looks like you're using the built-in version of Ruby that ships with macOS. Don't use system Ruby. I suggest installing a Ruby manager like RVM:

  1. Install RVM with

     \curl -sSL https://get.rvm.io | bash -s stable
  2. Restart your shell.

  3. Install Ruby with

     rvm install 2.7

Then reinstall your gems with bundle install.

Installing the PostgreSQL gem with 'gem pq' fails with ERROR: Failed to build gem native extension

If you are using Ubuntu try to install following lib file

sudo apt-get install libpq-dev

and then gem install pg

worked for me.

Installing pg gem; ERROR: Failed to build gem native extension

Using homebrew fixed this for me:

gem uninstall pg
brew install apple-gcc42
gem install pg

EDIT: I also manually installed "devtools"

xcode-select --install

Gem::Ext::BuildError: ERROR: Failed to build gem native extension trying to install postgresql

Because you're using the yum package manager, the package name is wrong. libpq-dev is the package name for the apt package manager. Try installing postgresql-libs. If that doesn't work, try postgresql-devel.

unable to install pg gem

Answered here:
Can't install pg gem on Windows

There is no Windows native version of
latest release of pg (0.10.0) released
yesterday, but if you install 0.9.0 it
should install binaries without
issues.

Postgresql Gem Not Installing

I managed to get the issue solved. The main issue was the pg version - 0.17.0. I installed the latest Postgres.app and verified the version was 0.17.1 upon installation. I then modified the gem file to simply gem 'pg' and ran bundle update. Thanks to everyone for the suggestions and links.

Windows: Installing pg gem fail with Can't find the PostgreSQL client library (libpq) and undefined reference to `PQconnectdb'

The issue was apparently being caused because I was using the 32 bit version of Ruby. Installed the 64 bit and the issue was resolved.

Rails pg gem, an error occurred while installing pg

I guess you don't have postgres installed in your system. You could either install postgresql via homebrew/macports or disable the installation of production gems with:

bundle install --without production


Related Topics



Leave a reply



Submit