Error installing pg gem on osx
Asked Answered
F

10

13

I am on osx 10.6.7 trying to run bundle install on a new rails 3.0.7 app and it keeps failing when trying to build the pg gem. It keeps telling me that I have need the developer tools. But as far as I can tell I have the developer tools installed.

Here is the output of xcodebuild -version

Xcode 3.2.6
Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
BuildVersion: 10M2518

Here is the output of the failed pg gem build

/Users/bm/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb --with-pg-config=/Library/PostgreSQL/8.4/bin/pg_config
Using config values from /Library/PostgreSQL/8.4/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=/Users/bm/.rvm/rubies/ruby-1.9.2-head/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
/Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
    from extconf.rb:31:in `<main>'


Gem files will remain installed in /Users/bm/.rvm/gems/ruby-1.9.2-head@rc_search/gems/pg-0.11.0 for inspection.
Results logged to /Users/bm/.rvm/gems/ruby-1.9.2-head@rc_search/gems/pg-0.11.0/ext/gem_make.out
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:486:in `block in build_extensions'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:446:in `each'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:446:in `build_extensions'
    from /Users/bm/.rvm/rubies/ruby-1.9.2-head/lib/ruby/1.9.1/rubygems/installer.rb:198:in `install'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/source.rb:100:in `install'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/installer.rb:55:in `block in run'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `block in each'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/spec_set.rb:12:in `each'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/installer.rb:44:in `run'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/installer.rb:8:in `install'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/cli.rb:217:in `install'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/gems/bundler-1.0.0/bin/bundle:13:in `<top (required)>'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/bin/bundle:19:in `load'
    from /Users/bm/.rvm/gems/ruby-1.9.2-head@global/bin/bundle:19:in `<main>'

Any help would be immensely appreciated. FYI I also tried building the app with a mysql and essentially got the same stack. So I'm pretty sure I'm missing some sort of developer build tools, but I just don't know which ones. :(

Fribble answered 23/4, 2011 at 4:17 Comment(2)
noted in a side comment that he does have an include directory with libpq-fe.h in it.Nonconductor
For that its worth, this ended up being the solution of me https://mcmap.net/q/467573/-gcc-4-9-1-in-os-x-yosemite-gcc-warning-couldn-t-understand-kern-osversion-14-0-0-39.Cesura
L
15

I had the exact same problem when running bundle install in a Rails app. I installed homebrew and then ran

brew install postgresql. 

That finally installed postgres correctly and the issue was fixed for me.

Lacerate answered 29/8, 2011 at 18:21 Comment(1)
yeah, and then just: env ARCHFLAGS="-arch x86_64" gem install pg.Earmuff
W
15
  1. export ARCHFLAGS='-arch x86_64'
  2. export PATH=/Library/PostgreSQL/9.1/bin:${PATH}
  3. gem install pg
Whosoever answered 16/1, 2012 at 14:1 Comment(1)
This worked for me, but I used macports to install postgres93 and so had to use: export PATH=$PATH:/opt/local/lib/postgresql93/binKerwon
B
7

If you are using the PostgreSQL app on osx, you may need to change path the following (as the location of the binaries and config files changes) instead of the path shown in lesyk's answer:

export PATH=/Applications/Postgres.app/Contents/MacOS/bin:${PATH}
Belly answered 31/8, 2013 at 23:59 Comment(0)
C
5

What worked for me was Zag Zag's comment:

~/projects/foo$ env ARCHFLAGS="-arch x86_64" gem install pg
Building native extensions.  This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Building YARD (yri) index for pg-0.11.0...

~/projects/foo$ bundle 
...
Using pg (0.11.0) 
...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Custody answered 20/11, 2011 at 22:39 Comment(0)
A
5

I had the same issue. For me the fix was:

sudo ln -s gcc /usr/bin/gcc-4.2

Allegorical answered 30/4, 2012 at 19:28 Comment(0)
M
2

I also ran into this issue, for me the answer was updating RVM of all things.

rvm get head
rvm install 1.9.2
Morula answered 3/5, 2012 at 11:49 Comment(0)
W
0

I'm on the same OSX and XCode version as you are: bundle install with pg 0.11.0 works fine to me. However, I found this article that might be able to help you fixing-the-you-have-to-install-development-tools-first-error-with-nokogiri

If you're using rvm, you can try:

rvm update head  
rvm --force install
1.9.2 gem install bundle

Here my stack:

[ 08:36:26 ] > bundle install
Fetching source index for http://rubygems.org/
Enter your password to install the bundled RubyGems to your system: 
Using rake (0.8.7) 
Using abstract (1.0.0) 
Installing activesupport (3.0.7) 
Installing builder (2.1.2) 
Installing i18n (0.5.0) 
Installing activemodel (3.0.7) 
Using erubis (2.6.6) 
Using rack (1.2.2) 
Installing rack-mount (0.6.14) 
Installing rack-test (0.5.7) 
Installing tzinfo (0.3.27) 
Installing actionpack (3.0.7) 
Using mime-types (1.16) 
Installing polyglot (0.3.1) 
Installing treetop (1.4.9) 
Installing mail (2.2.19) 
Installing actionmailer (3.0.7) 
Installing arel (2.0.9) 
Installing activerecord (3.0.7) 
Installing activeresource (3.0.7) 
Using bundler (1.0.10) 
Installing pg (0.11.0) with native extensions 
Using thor (0.14.6) 
Installing railties (3.0.7) 
Installing rails (3.0.7) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
[ ronda@MacBook ~/Projects/rails_projects/first_app ]
[ 08:42:57 ] > rails server
=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-04-27 20:45:27] INFO  WEBrick 1.3.1
[2011-04-27 20:45:27] INFO  ruby 1.9.2 (2011-02-18) [x86_64-darwin10]
[2011-04-27 20:45:27] INFO  WEBrick::HTTPServer#start: pid=4757 port=3000
Waterresistant answered 27/4, 2011 at 19:13 Comment(0)
M
0

The simple solution:

  1. run brew install postgresql
  2. install the gem with sudo permissions: like so: sudo gem install pg -v '0.17.1'
Martyrize answered 26/4, 2014 at 8:30 Comment(0)
F
0

I was stuck on my bundle install for 3 days. Tried Everything like adding env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

I was able to see pg gem getting installed after this command but still it was not installing from bundle install, which was a pain because I dint know what to write in Gemfile except gem 'pg'

The thing which finally worked for me was to find that my pg_config was in /Library/PostgreSQL/9.3/bin/pg_config and by default the Gemfile bundle install looks in /usr/local/bin/pg_config

I just ran the following command and magic happened. bundle config build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config

Forbidden answered 26/12, 2014 at 10:25 Comment(0)
F
0

Some correction. For those who have installed postgres using homebrew.

1) write the following line in your ~/.bash_profile

export ARCHFLAGS="-arch x86_64"

2) restart console

3) execute following command

bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config (this has to be your pg config address, can differ for each depending on versions of postgres)

4) Install pg once locally by running this command

sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config

5) bundle install

Forbidden answered 21/9, 2015 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.