Coding⏱️ 3 min read📅 2026-06-15

How to Fix: Linux - Gem Error installing PG

Gem error installing PG on Linux, solution involves installing development tools.

Quick Answer: Install the necessary development tools to resolve the Gem error installing PG on Linux.

Installing the PostgreSQL gem on Backtrack 5 can be frustrating when you encounter the 'Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension' error. This issue affects users who are trying to install the PG gem and have not yet installed the necessary development tools.

The error is caused by a lack of necessary libraries and/or headers, which can be resolved by installing the required packages. In this guide, we will walk you through the steps to resolve this issue.

⚠️ Common Causes

  • The primary reason for this error is that the system lacks the necessary development tools required for building native extensions. This can include things like a compiler, header files, and other dependencies.
  • An alternative cause could be issues with the configuration options provided by the gem installer.

🛠️ Step-by-Step Verified Fixes

Installing Required Development Tools

  1. Step 1: Open a terminal on your Backtrack 5 system and update the package list using the command 'apt-get update'. This will ensure that you have access to the latest package versions.
  2. Step 2: Install the necessary development tools using the command 'apt-get install build-essential libpq-dev libssl-dev'. These packages include a compiler, header files, and other dependencies required for building native extensions.
  3. Step 3: Verify that the installation was successful by checking the output of 'dpkg -l | grep postgresql'.

Configuring the Gem Installer

  1. Step 1: Open the gem installer configuration file using a text editor. The location of this file may vary depending on your system configuration.
  2. Step 2: Add the following configuration options to the file: '--with-pg-dir=/usr/lib/postgresql/9.3/bin' and '--with-pg-include=/usr/lib/postgresql/9.3/include'. These options specify the directory where the PostgreSQL installation is located and the include files for the PG gem.
  3. Step 3: Save the changes to the configuration file and attempt to install the PG gem again using the command 'gem install pg'.

🎯 Final Words

By following these steps, you should be able to resolve the 'Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension' error when installing the PG gem on Backtrack 5. Remember to always keep your system's package list up-to-date and install any necessary development tools before attempting to install gems.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions