Can't install pg gem on Mountain Lion

感情迁移 提交于 2019-12-28 02:53:09

问题


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.


回答1:


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!




回答2:


As banditKing says in his answer, need to tell the gem where to find the postgres binaries. You can use the binaries included with the excellent and easy postgres.app from Heroku ( http://postgresapp.com ) to install this gem instead of the EnterpriseDb version. The EnterpriseDB version is great, but an involved install for a dev machine.

Download Postgres.app on your system and add the internal bin directory to your path. I put it in /Applications/Postgres.app, so I used

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

worked for me on 10.8.2, Ruby 1.9.3, pg-0.14.1, and the XCode CLI tools




回答3:


Alternatively, use the Postgres app. IMO, it's the easiest and fastest way to get up and running with PostgreSQL and Rails on Mac.

For detailed instructions: http://blog.parsalabs.com/blog/2013/09/14/installing-postgresql-don-mac-os-x-and-using-it-as-your-rails-apps-database/




回答4:


After installing Mavericks bundle update was throwing an error on the pg gem.

I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.

The fix was to just brew uninstall postgresql, then brew install postgresql. After which I was immediately able to successfully run bundle update.



来源:https://stackoverflow.com/questions/12273815/cant-install-pg-gem-on-mountain-lion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!