Skip to content

Instantly share code, notes, and snippets.

@shu0115
Created April 12, 2012 13:24
Show Gist options
  • Save shu0115/2367193 to your computer and use it in GitHub Desktop.
Save shu0115/2367193 to your computer and use it in GitHub Desktop.
Error installing pg gem in Mac OS X
$ bundle install
----------------------------------------------------------------------------------------------------
Installing pg (0.13.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/raisondetre0115/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/raisondetre0115/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
Gem files will remain installed in /Users/raisondetre0115/.rvm/gems/ruby-1.9.3-p125/gems/pg-0.13.2 for inspection.
Results logged to /Users/raisondetre0115/.rvm/gems/ruby-1.9.3-p125/gems/pg-0.13.2/ext/gem_make.out
An error occured while installing pg (0.13.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.13.2'` succeeds before bundling.
----------------------------------------------------------------------------------------------------
$ brew install postgresql
----------------------------------------------------------------------------------------------------
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Installing postgresql dependency: readline
==> Downloading http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
######################################################################## 100.0%
==> Patching
patching file vi_mode.c
patching file callback.c
patching file support/shobj-conf
patching file patchlevel
==> ./configure --prefix=/usr/local/Cellar/readline/6.2.2 --mandir=/usr/local/Cellar/readline/6.2.2/share/man --infodir=/usr/local/Cellar/readline/6.2
==> make install
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.
OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
Generally there are no consequences of this for you.
If you build your own software and it requires this formula, you'll need
to add its lib & include paths to your build variables:
LDFLAGS -L/usr/local/Cellar/readline/6.2.2/lib
CPPFLAGS -I/usr/local/Cellar/readline/6.2.2/include
==> Summary
/usr/local/Cellar/readline/6.2.2: 30 files, 1.6M, built in 51 seconds
==> Installing postgresql dependency: ossp-uuid
==> Downloading ftp://ftp.ossp.org/pkg/lib/uuid/uuid-1.6.2.tar.gz
######################################################################## 100.0%
==> ./configure --disable-debug --without-perl --without-php --without-pgsql --prefix=/usr/local/Cellar/ossp-uuid/1.6.2
==> make
==> make install
/usr/local/Cellar/ossp-uuid/1.6.2: 12 files, 328K, built in 26 seconds
==> Installing postgresql
==> Downloading http://ftp.postgresql.org/pub/source/v9.1.3/postgresql-9.1.3.tar.bz2
######################################################################## 100.0%
==> ./configure --disable-debug --prefix=/usr/local/Cellar/postgresql/9.1.3 --datadir=/usr/local/Cellar/postgresql/9.1.3/share/postgresql --docdir=/us
==> make install-world
==> Caveats
# Build Notes
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
https://github.com/mxcl/homebrew/issues/issue/2510
To build plpython against a specific Python, set PYTHON prior to brewing:
PYTHON=/usr/local/bin/python brew install postgresql
See:
http://www.postgresql.org/docs/9.1/static/install-procedure.html
# Create/Upgrade a Database
If this is your first install, create a database with:
initdb /usr/local/var/postgres
To migrate existing data from a previous major version (pre-9.1) of PostgreSQL, see:
http://www.postgresql.org/docs/9.1/static/upgrading.html
# Start/Stop PostgreSQL
If this is your first install, automatically load on login with:
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
If this is an upgrade and you already have the homebrew.mxcl.postgresql.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
cp /usr/local/Cellar/postgresql/9.1.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or start manually with:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
And stop with:
pg_ctl -D /usr/local/var/postgres stop -s -m fast
# Loading Extensions
By default, Homebrew builds all available Contrib extensions. To see a list of all
available extensions, from the psql command line, run:
SELECT * FROM pg_available_extensions;
To load any of the extension names, navigate to the desired database and run:
CREATE EXTENSION [extension name];
For instance, to load the tablefunc extension in the current database, run:
CREATE EXTENSION tablefunc;
For more information on the CREATE EXTENSION command, see:
http://www.postgresql.org/docs/9.1/static/sql-createextension.html
For more information on extensions, see:
http://www.postgresql.org/docs/9.1/static/contrib.html
# Other
Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/current/static/kernel-resources.html#SYSVIPC
To install postgresql (and ossp-uuid) in 32-bit mode:
brew install postgresql --32-bit
If you want to install the postgres gem, including ARCHFLAGS is recommended:
env ARCHFLAGS="-arch x86_64" gem install pg
To install gems without sudo, see the Homebrew wiki.
==> Summary
/usr/local/Cellar/postgresql/9.1.3: 2739 files, 36M, built in 9.2 minutes
----------------------------------------------------------------------------------------------------
$ gem install pg
----------------------------------------------------------------------------------------------------
Building native extensions. This could take a while...
Successfully installed pg-0.13.2
1 gem installed
----------------------------------------------------------------------------------------------------
@franciscobeccaria
Copy link

franciscobeccaria commented May 27, 2021

This worked for me:

  • The error happens
  • brew install postgresql
  • brew services start postgresql
  • gem install pg
  • bundle install
  • success!

@ManasviniGanesh
Copy link

Thanks that was very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment