Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Impossible to Install PG gem on my mac with Mavericks

I'm trying to install the pg gem in order to work again with my rails projects. But I get this error:

Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension.

/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/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 --without-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/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby --with-pg --without-pg --with-pg-config --without-pg-config --with-pg_config --without-pg_config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/

Gem files will remain installed in /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0 for inspection. Results logged to /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out

I tried everything I found on stackoverflow but I still get this error.

If I try to install postgresql using brew I get the following waring:

Warning: postgresql-9.2.4 already installed, it's just not linked

If I try to link

brew link postgresql Linking /usr/local/Cellar/postgresql/9.2.4... Warning: Could not link postgresql. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7 /usr/local/share/man/man7 is not writable. You should change its permissions.

Help Please

NOTE: I already installed the command line tools for mavericks.


If I uninstall using homebrew and try to install again, I get this error:

==> Downloading http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2

################################################################## 100.0%

==> Patching patching file src/pl/plpython/Makefile patching file contrib/uuid-ossp/uuid-ossp.c ==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local/Cellar/p ==> 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

Create/Upgrade a Database

If this is your first install, create a database with: initdb /usr/local/var/postgres -E utf8

To migrate existing data from a previous major version (pre-9.2) of PostgreSQL, see:
http://www.postgresql.org/docs/9.2/static/upgrading.html

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.2/static/sql-createextension.html For more information on extensions, see:
http://www.postgresql.org/docs/9.2/static/contrib.html

Other

Some machines may require provisioning of shared memory:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC When installing the postgres gem, including ARCHFLAGS is recommended: ARCHFLAGS="-arch x86_64" gem install pg

To install gems without sudo, see the Homebrew wiki.

To have launchd start postgresql at login: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't want/need launchctl, you can just run: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start Warning: Could not link postgresql. Unlinking... Error: The brew link step did not complete successfully The formula built, but is not symlinked into /usr/local You can try again using `brew link postgresql' ==> Summary 🍺 /usr/local/Cellar/postgresql/9.2.4: 2831 files, 38M, built in 4.9 minutes


SOLUTION:

I execute this command in order to change the permission of the folder:

sudo chown jeanosorio /usr/local/share/man/man7

Then

brew link postgresql Linking /usr/local/Cellar/postgresql/9.3.1... 421 symlinks created

And finally:

sudo ARCHFLAGS="-arch x86_64" gem install pg

Fetching: pg-0.17.0.gem (100%) Building native extensions. This could take a while... Successfully installed pg-0.17.0

like image 874
Jean Avatar asked Oct 28 '13 00:10

Jean


1 Answers

If you want to avoid using MacPorts, you can download the Postgres App and place it into the Application directory.

Then, specify the location of newly downloaded pg_config:

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config 

If you run in to missing headers problem, try specifying the include directory of the app:

gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/Versions/latest/include/' 
like image 194
Yuri Avatar answered Sep 18 '22 13:09

Yuri