在 osx 上安装 pg gem 时出错
Posted
技术标签:
【中文标题】在 osx 上安装 pg gem 时出错【英文标题】:Error installing pg gem on osx 【发布时间】:2011-08-11 08:27:56 【问题描述】:我在 osx 10.6.7 上尝试在新的 rails 3.0.7 应用程序上运行 bundle install,但在尝试构建 pg gem 时它一直失败。它一直告诉我我需要开发人员工具。但据我所知,我已经安装了开发者工具。
这是 xcodebuild -version 的输出
Xcode 3.2.6
Component versions: DevToolsCore-1809.0; DevToolsSupport-1806.0
BuildVersion: 10M2518
这是失败的 pg gem 构建的输出
/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>'
任何帮助将不胜感激。仅供参考,我还尝试使用 mysql 构建应用程序,并且基本上得到了相同的堆栈。所以我很确定我错过了某种开发人员构建工具,但我只是不知道哪些。 :(
【问题讨论】:
在旁注中指出,他确实有一个include
目录,其中包含libpq-fe.h
。
为了它的价值,这最终成为我***.com/a/26609483/1438478的解决方案。
【参考方案1】:
我使用与您相同的 OSX 和 XCode 版本:使用 pg 0.11.0 进行捆绑安装对我来说效果很好。 但是,我发现这篇文章可能会对您有所帮助 fixing-the-you-have-to-install-development-tools-first-error-with-nokogiri
如果你使用的是rvm,你可以试试:
rvm update head
rvm --force install
1.9.2 gem install bundle
这是我的堆栈:
[ 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
【讨论】:
【参考方案2】:在 Rails 应用程序中运行 bundle install 时,我遇到了完全相同的问题。我安装了自制软件,然后运行
brew install postgresql.
终于正确安装了 postgres,问题也为我解决了。
【讨论】:
是的,然后就是:env ARCHFLAGS="-arch x86_64" gem install pg
。【参考方案3】:
对我有用的是 Zag Zag 的评论:
~/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.
【讨论】:
【参考方案4】:-
export ARCHFLAGS='-arch x86_64'
导出 PATH=/Library/PostgreSQL/9.1/bin:$PATH
gem 安装 pg
【讨论】:
这对我有用,但我使用 macports 安装 postgres93,因此不得不使用:export PATH=$PATH:/opt/local/lib/postgresql93/bin
【参考方案5】:
我有同样的问题。对我来说,解决方法是:
sudo ln -s gcc /usr/bin/gcc-4.2
【讨论】:
【参考方案6】:我也遇到了这个问题,对我来说,答案是更新所有东西的 RVM。
rvm get head
rvm install 1.9.2
【讨论】:
【参考方案7】:如果您在 osx 上使用 PostgreSQL 应用程序,您可能需要更改以下路径(随着二进制文件和配置文件的位置更改),而不是 lesyk 的答案中显示的路径:
export PATH=/Applications/Postgres.app/Contents/MacOS/bin:$PATH
【讨论】:
【参考方案8】:简单的解决方案:
-
运行
brew install postgresql
使用 sudo 权限安装 gem:像这样:
sudo gem install pg -v '0.17.1'
【讨论】:
【参考方案9】:我的捆绑包安装卡住了 3 天。尝试了所有方法,例如添加 env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config p>
我能够看到在这个命令之后安装了 pg gem,但它仍然没有从 bundle install 安装,这很痛苦,因为除了 gem 'pg' 之外我不知道在 Gemfile 中要写什么
最终对我有用的是发现我的 pg_config 在 /Library/PostgreSQL/9.3/bin/pg_config 中,默认情况下 Gemfile 包安装在 /usr/local/bin 中/pg_config
我刚刚运行了以下命令,神奇的事情发生了。 捆绑配置 build.pg --with-pg-config=/Library/PostgreSQL/9.3/bin/pg_config
【讨论】:
【参考方案10】:一些修正。对于那些使用自制软件安装了 postgres 的人。
1) 在 ~/.bash_profile 中写入以下行
导出 ARCHFLAGS="-arch x86_64"
2) 重启控制台
3) 执行以下命令
bundle config build.pg --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config(这必须是你的pg配置地址,可以根据 postgres 的版本而有所不同)
4) 通过运行此命令在本地安装一次 pg
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.3.5_1/bin/pg_config
5) 捆绑安装
【讨论】:
以上是关于在 osx 上安装 pg gem 时出错的主要内容,如果未能解决你的问题,请参考以下文章
Rails:在 OS X 上安装 PG gem - 无法构建本机扩展
运行 gem install pg -v '0.15.1' 时出错
安装 pg (0.17.1) 时出错,Bundler 无法继续