gpt4 book ai didi

ruby-on-rails - 无法在 Mountain Lion 上安装 pg gem

转载 作者:行者123 更新时间:2023-11-29 11:18:22 25 4
gpt4 key购买 nike

升级到 Mountain Lion 后,我在使用 Rails 时遇到了很多麻烦。

到目前为止,为了解决这些问题并在互联网上搜索了几个小时,我已经完成了以下操作,以确保我的系统具有在升级后运行 rails 的所有依赖项:

  1. 我更新了 Homebrew 安装
  2. 我更新了我的 RVM 安装
  3. 我安装了 XCode 命令行工具
  4. 我安装了 GCC as mentioned
  5. 我将我的 Ruby 版本升级到了

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

  6. 我的 Rails 版本已验证为 Rails 3.2.6
  7. 我还发现 Mountain Lion 与 Postgres 有一些问题,所以我看到了 this post并发现我需要将这一行添加到我的 Bash 配置文件中:

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

现在我转到升级前在 Snow Leopard 上运行良好的 Rails 应用程序,当我在命令行运行 rails s 时,出现以下错误:

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

当我转到 Rails 应用并尝试 bundle install 时,它在 pg 安装时失败。

最佳答案

http://www.enterprisedb.com/products-services-training/pgdownload#osx 下载 postgresSQL 安装程序

然后让你的路径看起来像这样:

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

这样就可以了!

注意:请在路径中正确指定您安装的 postgreSQL 版本。

更新(10/11/2015)(取自Heroku)

在带有 Homebrew 的 OS X 上:

  1. 使用以下方法安装 postgresql:

    brew 安装 postgresql

  2. 然后使用以下命令安装 gem:

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

在带有 MacPorts 的 OS X 上:

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

希望这对您有所帮助!

关于ruby-on-rails - 无法在 Mountain Lion 上安装 pg gem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12273815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com