Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

ruby on rails - Can't install pg gem on Mountain Lion

I have been having a lot of troubles with Rails after upgrading to Mountain Lion.

Trying to trouble shoot these and searching for hours on the internet so far I have done the following to ensure my system has all the dependencies to run rails after the upgrade:

  1. I updated my Homebrew installation
  2. I updated my RVM installation
  3. I installed the XCode command line tools
  4. I installed GCC as mentioned
  5. I upgraded my version of Ruby to

    ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]

  6. My Rails version is verified as Rails 3.2.6
  7. I also found out that Mountain Lion has some issues with Postgres so I saw this post and found out that I need to add this line to my Bash profile:

    export PATH="/usr/local/bin:/usr/bin:$PATH"
    

Now I go to my Rails app that used to run fine on Snow Leopard before I upgraded, and when I run rails s at the command line I get the following error:

AM@~/Documents/RailsWS/app0815 >gem install pg
 Building native extensions.  This could take a while...
 ERROR:  Error installing pg:
 ERROR: Failed to build gem native extension.
 /Users/AM/.rvm/rubies/ruby-1.9.2-p290/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
--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/AM/.rvm/rubies/ruby-1.9.2-p290/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
 /Users/AM/.rvm/rubies/ruby-1.9.2-p290/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/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:853:in `block in   find_header'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block (2  levels) in postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
from extconf.rb:41:in `<main>'


 Gem files will remain installed in /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.14.1 for inspection.
 Results logged to /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.14.1/ext/gem_make.out

When I go to the Rails app and try bundle install it fails at pg installation.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Download the postgresSQL installer from http://www.enterprisedb.com/products-services-training/pgdownload#osx

and then make your path look something like this:

PATH=$PATH:/Library/PostgreSQL/9.0/bin/ gem install pg

This would do!

Note: Please specify your postgreSQL installed version correctly in the path.

UPDATE(10/11/2015) (Taken from Heroku)

On OS X with Homebrew:

  1. Install postgresql using:

    brew install postgresql

  2. Then install the gem using:

    gem install pg -- --with-pg-config=/usr/local/bin/pg_config

On OS X with MacPorts:

gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config

Hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...