Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to install pg gem fails during ruby project build

I'm attempting to build a ruby project which uses postgres running locally. Build fails on the pg gem install. I get this error

$ gem install pg -v '0.12.2'
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

    /path/to/.rvm/rubies/ruby-1.9.3-p545/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

so... I pass the pg_config path, and get a different error:

$ gem install pg --with-pg-config=/usr/pgsql-9.2/bin/pg_config -v '0.12.2'
ERROR:  While executing gem ... (OptionParser::InvalidOption)
    invalid option: --with-pg-config=/usr/pgsql-9.2/bin/pg_config

Very confused.

like image 382
etsauer Avatar asked Mar 27 '14 14:03

etsauer


1 Answers

Make sure you have libpq-dev package installed. If you don't, install it and try installing pg again without the --with-pg-config parameter.

In regards to the --with-pg-config parameter:

When passing parameters to the gem you're installing you must use two dashes before the two dashes from the option, like so:

gem install gem-name -- --gem-option

So what you want to run in order to achieve installing pg with the --with-pg-config option is:

gem install pg -v '0.12.2' -- --with-pg-config=/usr/pgsql-9.2/bin/pg_config

EDIT

Also, one last tip, after searching a bit more about this issue I found that your ruby version and architecture might affect pg's installation, I'm quoting this link:

I was hesitant to uninstall everything so I just uninstalled Ruby and reinstalled with the option set to 64-bit only (platform: "x86_64-darwin12.2.0"). After reinstalling Ruby with this option, the PG gem installed without hitch and I am back to being happy.

like image 191
JeanLescure Avatar answered Nov 15 '22 03:11

JeanLescure