pg gem install error - lion osx, bundler, and rvm - ruby-on-rails

I have spent way too many hours trying to fix this.
I reformatted my computer - clean snow leopard, than immediate upgrade to lion.
Xcode 4.2.1 installed
RVM installed
As I setup my environment I finally got to bundle install, and it failed trying to create the PG gem.
I had installed postgresql using macports (wasn't aware its preinstalled in lion). Following instructions here:http://benscheirman.com/2010/06/installing-postgresql-for-rails-on-mac-os-x And ran into more errors trying to install the pg gem:
Installing pg (0.12.0) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/me/.rvm/rubies/ruby-1.8.7-p357/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/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/sling31/.rvm/rubies/ruby-1.8.7-p357/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/me/.rvm/gems/ruby-1.8.7-p357/gems/pg-0.12.0 for inspection.
Results logged to /Users/me/.rvm/gems/ruby-1.8.7-p357/gems/pg-0.12.0/ext/gem_make.out
An error occured while installing pg (0.12.0), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.0'` succeeds before bundling.
I've searched stackoverflow nonstop, and pretty much tried everything.
I removed the macports version, and then decided to try installing with homebrew:
"brew install postgresql"
pg_config gives me:
BINDIR = /usr/local/Cellar/postgresql/9.1.2/bin
DOCDIR = /usr/local/Cellar/postgresql/9.1.2/share/doc/postgresql
HTMLDIR = /usr/local/Cellar/postgresql/9.1.2/share/doc/postgresql
INCLUDEDIR = /usr/local/Cellar/postgresql/9.1.2/include
PKGINCLUDEDIR = /usr/local/Cellar/postgresql/9.1.2/include
INCLUDEDIR-SERVER = /usr/local/Cellar/postgresql/9.1.2/include/server
LIBDIR = /usr/local/Cellar/postgresql/9.1.2/lib
PKGLIBDIR = /usr/local/Cellar/postgresql/9.1.2/lib
LOCALEDIR = /usr/local/Cellar/postgresql/9.1.2/share/locale
MANDIR = /usr/local/Cellar/postgresql/9.1.2/share/man
SHAREDIR = /usr/local/Cellar/postgresql/9.1.2/share/postgresql
SYSCONFDIR = /usr/local/Cellar/postgresql/9.1.2/etc
PGXS = /usr/local/Cellar/postgresql/9.1.2/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--disable-debug' '--prefix=/usr/local/Cellar/postgresql/9.1.2' '--enable-thread-safety' '--with-bonjour' '--with-gssapi' '--with-krb5' '--with-openssl' '--with-libxml' '--with-libxslt' '--with-python' '--with-perl' '--with-ossp-uuid' '--datadir=/usr/local/Cellar/postgresql/9.1.2/share/postgresql' '--docdir=/usr/local/Cellar/postgresql/9.1.2/share/doc/postgresql' 'ARCHFLAGS='''-arch x86_64'''' 'CC=/usr/bin/llvm-gcc' 'CFLAGS=-O3 -w -pipe -march=core2 -msse4.1 -I/opt/local/include/ossp' 'LDFLAGS=-L/usr/local/Cellar/readline/6.2.2/lib -L/opt/local/lib' 'LIBS=-luuid' 'CPPFLAGS=-I/usr/local/Cellar/readline/6.2.2/include -I/usr/include/libxml2'
CC = /usr/bin/llvm-gcc
CPPFLAGS = -I/usr/local/Cellar/readline/6.2.2/include -I/usr/include/libxml2 -I/opt/local/include/libxml2
CFLAGS = -O3 -w -pipe -march=core2 -msse4.1 -I/opt/local/include/ossp -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wformat-security -fno-strict-aliasing -fwrapv
CFLAGS_SL =
LDFLAGS = -L/usr/local/Cellar/readline/6.2.2/lib -L/opt/local/lib -L/opt/local/lib -Wl,-dead_strip_dylibs
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgport -lxslt -lxml2 -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm -luuid
VERSION = PostgreSQL 9.1.2
I tried all of the export rvm_archflags="-arch x86_64" type solutions, but none seemed to make any difference.
Any ideas where I should begin?

I'm not familiar with Brew, but it looks like the pg_config you're invoking is not the one used to configure pg.
So, please try include /usr/local/Cellar/postgresql/9.1.2/bin (expect to have pg_config there) to the path and retry.
Actually, the output says "Using config values from /usr/local/bin/pg_config"
it should be the pg_config in the Brew's path. I guess it's in /usr/local/Cellar/postgresql/9.1.2/bin .

This might help: https://plus.google.com/104769575749979987265/posts/CVdrNMZYU9R
It does for Linux anyways.

Related

`gem install sqlite3` tells me to `brew install sqlite3`, but it appears to be already installed on my system -- how do I resolve?

Thanks for any help with this issue, I know there's a lot of different threads around ruby sqlite3 gem install issues. However, I'm facing a specific issue, where by all appearances, it seems sqlite3 is installed on my system, yet unable to be found by the ruby sqlite3 gem install.
I've outlined below that I'm able to see sqlite3 installed on my system, yet I get an error when trying to gem install sqlite3:
checking for sqlite3_libversion_number() in -lsqlite3...
no
sqlite3 is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
I seem to get this same error, even if I use the: --with-sqlite3-dir option, setting it to the directory I see in which sqlite3.
Does anyone know what I'm doing wrong, why the sqlite3 ruby gem can't find my system sqlite3 library? Do I need to update something else somewhere, or something in the errors I'm overlooking? Any help is graciously appreciated!
Details below:
Verify sqlite3 is installed on my system (macOS)
sqlite3 --version
> 3.36.0 2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5
which sqlite3
> /opt/homebrew/opt/sqlite/bin/sqlite3
Attempt to install the sqlite3 gem
However, if I attempt to install the gem file via:
gem install sqlite3
I get the error:
sqlite3 is missing
Full output:
twknab#tk-mac-mini my-cool-project % gem install sqlite3
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
current directory: /Users/twknab/.rvm/gems/ruby-3.0.2/gems/sqlite3-1.4.2/ext/sqlite3
/Users/twknab/.rvm/rubies/ruby-3.0.2/bin/ruby -I /Users/twknab/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0 -r ./siteconf20211113-2417-45lgod.rb extconf.rb
checking for sqlite3.h... yes
checking for pthread_create() in -lpthread... yes
checking for -ldl... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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/twknab/.rvm/rubies/ruby-3.0.2/bin/$(RUBY_BASE_NAME)
--with-sqlcipher
--without-sqlcipher
--with-sqlcipher
--without-sqlcipher
--with-sqlite3-config
--without-sqlite3-config
--with-pkg-config
--without-pkg-config
--with-sqlcipher
--without-sqlcipher
--with-sqlite3-dir
--without-sqlite3-dir
--with-sqlite3-include
--without-sqlite3-include=${sqlite3-dir}/include
--with-sqlite3-lib
--without-sqlite3-lib=${sqlite3-dir}/lib
--with-pthread-dir
--without-pthread-dir
--with-pthread-include
--without-pthread-include=${pthread-dir}/include
--with-pthread-lib
--without-pthread-lib=${pthread-dir}/lib
--with-pthreadlib
--without-pthreadlib
--with-dl-dir
--without-dl-dir
--with-dl-include
--without-dl-include=${dl-dir}/include
--with-dl-lib
--without-dl-lib=${dl-dir}/lib
--with-dllib
--without-dllib
--with-sqlcipher
--without-sqlcipher
--with-sqlite3lib
--without-sqlite3lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/twknab/.rvm/gems/ruby-3.0.2/extensions/arm64-darwin-21/3.0.0/sqlite3-1.4.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/twknab/.rvm/gems/ruby-3.0.2/gems/sqlite3-1.4.2 for inspection.
Results logged to /Users/twknab/.rvm/gems/ruby-3.0.2/extensions/arm64-darwin-21/3.0.0/sqlite3-1.4.2/gem_make.ou
Installing sqlite3 gem but setting directory
I've also tried setting the directory when installing the gem to the same which is returned by which sqlite3, but get the same error saying sqlite3 is not found on my system:
gem install sqlite3 --with-sqlite3-dir=/opt/homebrew/opt/sqlite/bin/sqlite3
I get the same error:
sqlite3 is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
(And the same full output as above)
Other Notes
If I checkout the mkmf.log as noted at the end of the output, I do see some stuff like this:
"pkg-config --exists sqlite3"
| pkg-config --libs sqlite3
=> "-L/opt/homebrew/Cellar/sqlite/3.36.0/lib -lsqlite3\n"
"gcc -fdeclspec -o conftest -I/Users/twknab/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0/arm64-darwin21 -I/Users/twknab/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0/ruby/backward -I/Users/twknab/.rvm/rubies/ruby-3.0.2/include/ruby-3.0.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/openssl#1.1/include -fno-common -pipe conftest.c -L. -L/Users/twknab/.rvm/rubies/ruby-3.0.2/lib -L. -L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/libksba/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/openssl#1.1/lib -fstack-protector-strong -L/usr/local/lib -m64 -lruby.3.0 "
ld: warning: ignoring file /Users/twknab/.rvm/rubies/ruby-3.0.2/lib/libruby.3.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return !!argv[argc];
6: }
Specifically noting:
ld: warning: ignoring file /Users/twknab/.rvm/rubies/ruby-3.0.2/lib/libruby.3.0.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
I'm running on an M1 apple silicon. Any thoughts if this might be part of the problem? Having trouble making sense of these logs
Could solve it with:
sudo gem install sqlite3 -v '1.4.2' -- --with-sqlite3-lib=/usr/lib
and then:
bundle config build.sqlite3 --with-sqlite3-lib=/usr/lib

Using postgres as default in rails

I'm a newbie in ruby and rails development. I know that rails uses sqlite3 as default, so I want to try using postgres as defalut. I've downloaded postgres, jruby, ruby 2.5.1, rails 5.2.1. I've intalled ruby devkit with ruby dk.rb init/install. I'm stumbled into the wall when I try to install pg gem, I get the following output:
Building native extensions. This could take a while...
C:/jruby-9.1.17.0/lib/ruby/stdlib/rubygems/ext/ext_conf_builder.rb:58: warning: Tempfile#unlink or delete called on open file; ignoring
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
current directory: C:/jruby-9.1.17.0/lib/ruby/gems/shared/gems/pg-1.1.3/ext
C:/jruby-9.1.17.0/bin/jruby.exe -r ./siteconf20180918-6200-16mdyzt.rb extconf.rb
checking for pg_config... yes
Using config values from C:\postgres\bin/pg_config.exe
RuntimeError: The compiler failed to generate an executable file.
You have to install development tools first.
try_do at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:456
try_link0 at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:541
try_link at C:/jruby-9.1.17.0/lib/ruby/stdlib/mkmf.rb:556
<main> at extconf.rb:40
*** 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=C:/jruby-9.1.17.0/bin/jruby
--with-pg
--without-pg
--enable-windows-cross
--disable-windows-cross
--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}/lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/jruby-9.1.17.0/lib/ruby/gems/shared/extensions/universal-java-1.8/2.3.0/pg-1.1.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/jruby-9.1.17.0/lib/ruby/gems/shared/gems/pg-1.1.3 for inspection.
Results logged to C:/jruby-9.1.17.0/lib/ruby/gems/shared/extensions/universal-java-1.8/2.3.0/pg-1.1.3/gem_make.out
mkmf.log contains:
find_executable: checking for pg_config... -------------------- yes
--------------------
" -o conftest.exe -I/include/universal-java1.8 -IC:/jruby-9.1.17.0/lib/ruby/include/ruby/backward -IC:/jruby-9.1.17.0/lib/ruby/include -I. -IC:/postgres/include -fno-omit-frame-pointer -fno-strict-aliasing -fexceptions conftest.c -L. -LC:/jruby-9.1.17.0/lib -LC:/postgres/lib -LC:/jruby-9.1.17.0/lib/native/x86_64-Windows -m64 -march=native -mtune=native "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <ruby.h>
4: int main(int argc, char **argv)
5: {
6: return 0;
7: }
/* end */
Have you installed postgres package in your system You can install in linux using command
sudo apt-get install postgresql postgresql-contrib
if you are using debian system
The error clearly states that that you need to install development tools so you may have likely missed installing some dependencies
You can install through command line utitlities using the commands
#powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://s3.amazonaws.com/pgcentral/install.ps1'))"
cd bigsql
pgc install pg10
pgc start pg10
Please follow this link to configure postgress in windows
To install postgres client, please refer to this stackoverflow link and also try to install pg gem by specifying the path of pgconfig file you can refer to this
link for example

Install pg gem on CentOS 6

I'm trying to setup my VPS (CentOS 6.4) with ruby on rails and postgres.
I installed ruby (2.1.0p0), rails (4.1.0), and postgresql (9.3.4) with no problem.
When I try create new rails app (rails new new_app -d postgresql) it stops when installing the pg gem. I've looked into all SO posts about this error and tried pretty much everything I could find. The most suggested was to run "yum install postgresql-devel" and still didn't work.
Below you can find the ssh output and the mkmf.log. Let me know if need more information...
Output
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/deploy/.rvm/rubies/ruby-2.1.0/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... *** 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=/home/deploy/.rvm/rubies/ruby-2.1.0/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}/lib
/home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:587:in `try_cpp'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1120:in `block in find_header'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:918:in `block in checking_for'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block (2 levels) in postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:351:in `block in postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:321:in `open'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:347:in `postpone'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:917:in `checking_for'
from /home/deploy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/mkmf.rb:1119:in `find_header'
from extconf.rb:48:in `'
extconf failed, exit code 1
mkmf.log
"gcc -o conftest -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/x86_64-linux -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0/ruby/backward -I/home/deploy/.rvm/rubies/ruby-2.1.0/include/ruby-2.1.0 -I. -I/usr/include -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -fPIC conftest.c -L. -L/home/deploy/.rvm/rubies/ruby-2.1.0/lib -Wl,-R/home/deploy/.rvm/rubies/ruby-2.1.0/lib -L/usr/lib64 -Wl,-R/usr/lib64 -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-rpath,'/../lib' -Wl,-R -Wl,'/../lib' -L'/../lib' -lruby -lpthread -lrt -ldl -lcrypt -lm -lc"
gcc: error trying to exec 'as': execvp: Permission denied
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
Before:
For Centos 6: Right install Postgres 9.* with this guide.
After:
yum install postgresql-libs postgresql-devel
Helpful instruction:
How to setup RoR with Postgres
As you are not using the outdated PostgreSQL version that comes with CentOS 6 (PostgreSQL 8.4), you need to install the -devel package matching your version (PostgreSQL 9.X).
The easiest way is to use the official PostgreSQL yum repository.
As the latest version is 9.5 and it is compatible with all 9.X versions I will write the instructions for that one. In the future you can refer to the official instructions for the updated commands.
yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm
yum install postgresql95-devel
Then install the gem with the -with-pg-config option:
gem install pg -- --with-pg-config=/usr/pgsql-9.5/bin/pg_config
This was easier for me:
ln -s /usr/pgsql-9.5/bin/pg_config /usr/local/bin/
Try something like this;
before "bundle:install" do
run "ls -l #{fetch(:latest_release)}/Gemfile"
#run "bundle config --local --gemfile=#{fetch(:latest_release)}/Gemfile build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config"
run "cd #{fetch(:latest_release)} && bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config"
end
You could try installing the pg gem with the postres pg_config file path option:
gem install pg -- --with-pg-config=/usr/pgsql-9.2/bin/pg_config
Please update the path according to your system
Regards
I had this problem on my mac and it was a bash / RVM issue. I had to add this to my bash:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm” . Given that it's finding the config file I would look into this.

Error updating pg gem from 0.17.0 to 0.17.1 for Mac OS X 10.9.1

Just did a simple bundle update and got an annoying error related to the pg gem for PostgreSQL. I don't have PostgreSQL installed on my system (unless it's automatically installed for Mac OS X 10.9.1). This has never been an issue before. Any ideas?
Using jquery-rails (3.0.4)
Using jquery-rails-cdn (1.0.1)
Installing liquid (2.6.1)
Using paperclip (3.5.2)
Installing pg (0.17.1)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/scott/.rvm/rubies/ruby-1.9.3-p194/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/scott/.rvm/rubies/ruby-1.9.3-p194/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}/lib
Gem files will remain installed in /Users/scott/.rvm/gems/ruby-1.9.3-p194#ucode/gems/pg-0.17.1 for inspection.
Results logged to /Users/scott/.rvm/gems/ruby-1.9.3-p194#ucode/gems/pg-0.17.1/ext/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.
$ gem list pg
*** LOCAL GEMS ***
pg (0.17.0, 0.16.0, 0.15.1, 0.15.0, 0.14.1)
UPDATE: as requested, this is my mkmf.log file
find_executable: checking for pg_config... -------------------- no
--------------------
find_header: checking for libpq-fe.h... -------------------- no
"/usr/bin/gcc-4.2 -o conftest -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin12.2.0 -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/include -fno-common -pipe conftest.c -L. -L/Users/scott/.rvm/rubies/ruby-1.9.3-p194/lib -L. -L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib -lruby.1.9.1 -lpthread -ldl -lobjc "
ld: warning: directory not found for option '-L/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/lib'
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
"/usr/bin/gcc-4.2 -E -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/x86_64-darwin12.2.0 -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1/ruby/backward -I/Users/scott/.rvm/rubies/ruby-1.9.3-p194/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/Users/mpapis/.rvm/rubies/ruby-1.9.3-p194/include -fno-common -pipe conftest.c -o conftest.i"
conftest.c:3:10: fatal error: 'libpq-fe.h' file not found
#include <libpq-fe.h>
^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <libpq-fe.h>
/* end */
--------------------
UPDATE 2: The only mention of pg in my Gemfile is here:
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
The easiest way is to install Postgres.app.
Then do:
$ gem install pg -v '0.17.1' && bundle update
Edit: Do not forget to add the relevant directories into your PATH.
try reinstall pg gem gem install pg --with-pg-config=/path/to/pg_config
I recomended install this app Postgres
and install gem:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
check this blog this guy have a details explanation of how to do this
http://wikimatze.de/installing-postgresql-gem-under-ubuntu-and-mac.html
Newbie here. I had the same error after doing a git clean -xdf. For some reason after I did this I could not start my local rails server nor would bundle install / update work giving the same pg gem errors. It was basically ignoring the following in my gemfile:
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
I was able to fix things by running the following line again. I guess it's set this back to default as I can now also just use bundle install when making updates.
bundle install --without production

Rails wants pg 0.10.0 but I can only install pg 0.10.1

I'm on Mac OS X. If I run sudo env ARCHFLAGS="-arch i386" gem install pg, it works just fine. However, I get this error when I try to visit my Rails project in the browser:
Could not find pg-0.10.0 in any of the sources (Bundler::GemNotFound)
If I then uninstall 0.10.1 and try to install 0.10.0, I get this:
$ sudo env ARCHFLAGS="-arch i386" gem install pg --version 0.10.0
Password:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for pg_config... yes
Ruby cflags: "-arch i386 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common "
MacOS X build: fixing architecture flags:
using the value in ARCHFLAGS environment variable ("-arch i386").
finding flags common to both Ruby and PostgreSQL...
testing for architecture: "ppc"
testing for architecture: "i386"
common arch flags: -arch i386
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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
--with-pg
--without-pg
--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}/lib
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/pg-0.10.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/pg-0.10.0/ext/gem_make.out
I don't care whether I find a way to make Rails accept pg 0.10.1 or if I find a way to install pg 0.10.0, but I need to do one or the other.
Is version 0.10.0 listed in your Gemfile.lock? If so, you should be able to update the version Rails is looking for by running bundle update pg, assuming your Gemfile doesn't also specify version 0.10.0.

Resources