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.
Install brew with
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
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:
Install RVM with
\curl -sSL https://get.rvm.io | bash -s stable
Restart your shell.
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
How to Debug Http of Ruby Google-Api-Client
Instance_Eval Block Not Supplied
How to Update Ruby with Homebrew
How to Get Activerecord Associations via Reflection
Disable a Group of Tests in Rspec
Attr_Accessor on Class Variables
Rails: Hasmanythroughassociationnotfounderror
Ruby Greed Koan - How to Improve My If/Then Soup
Rake Aborted, Error While Trying to Load the Gem 'Uglifier'
How to Call Java API from Ruby 1.8 or 1.9
Get SASS from Database (Compile Passed Data Instead of Reading from File)
Openssl VS Gpg for Encrypting Off-Site Backups
Ruby Convert Array into Function Arguments
Raise Custom Exception with Arguments