【发布时间】:2013-11-06 16:13:12
【问题描述】:
我正在尝试安装 pg gem,以便再次使用我的 rails 项目。但我得到这个错误:
构建原生扩展。这可能需要一段时间... 错误:错误 安装 pg: 错误: 无法构建 gem 原生扩展。
/Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb checking for pg_config... no No pg_config... trying anyway. If构建失败,请重试 --with-pg-config=/path/to/pg_config 检查 libpq-fe.h... 否 找不到 'libpq-fe.h 标头 * extconf.rb failed * 由于某种原因无法创建 Makefile,可能缺少必要的库和/或头文件。查看 mkmf.log 文件以获取更多详细信息。您可能需要配置 选项。
提供的配置选项:--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/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/bin/ruby --with-pg --without-pg --with-pg-config --without-pg-config --with-pg_config --without-pg_config --with-pg-dir --without-pg-dir --with-pg-include --without-pg-include=${pg-dir}/include --with-pg-lib --without-pg-lib=${pg-dir}/
Gem 文件将继续安装在 /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0 供检查。结果记录到 /Users/jeanosorio/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/pg-0.17.0/ext/gem_make.out
我尝试了在 stackoverflow 上找到的所有内容,但仍然出现此错误。
如果我尝试使用 brew 安装 postgresql,我会收到以下警告:
警告:postgresql-9.2.4 已经安装,只是没有链接
如果我尝试链接
brew 链接 postgresql 链接 /usr/local/Cellar/postgresql/9.2.4... 警告:无法链接 postgresql。取消链接...
错误:无法符号链接文件: /usr/local/Cellar/postgresql/9.2.4/share/man/man7/WITH.7 /usr/local/share/man/man7 不可写。你应该改变它 权限。
请帮忙
注意:我已经为 Mavericks 安装了命令行工具。
如果我使用自制软件卸载并尝试再次安装,我会收到此错误:
==> 正在下载http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.bz2
################################################# ################ 100.0%==> 打补丁 打补丁文件 src/pl/plpython/Makefile打补丁文件 contrib/uuid-ossp/uuid-ossp.c ==> ./configure --prefix=/usr/local/Cellar/postgresql/9.2.4 --datadir=/usr/local/Cellar/postgresql/9.2.4/share/postgresql --docdir=/usr/local /地窖/p ==> 制作安装世界 ==>注意事项
构建说明
如果 PostgreSQL 9 的构建失败并且您使用的是 8.x 版 安装,您可能需要先删除以前的版本。见:
https://github.com/mxcl/homebrew/issues/issue/2510创建/升级数据库
如果这是您的第一次安装,请使用以下命令创建数据库:initdb /usr/local/var/postgres -E utf8
从以前的主要版本(9.2 之前)迁移现有数据 PostgreSQL,见:
http://www.postgresql.org/docs/9.2/static/upgrading.html加载扩展
默认情况下,Homebrew 构建所有可用的 Contrib 扩展。看到一个 所有可用扩展的列表,从 psql 命令行运行:
选择 * FROM pg_available_extensions;要加载任何扩展名,请导航到所需的数据库 并运行:CREATE EXTENSION [扩展名];
例如,要在当前数据库中加载 tablefunc 扩展, 运行:创建扩展表函数;
有关 CREATE EXTENSION 命令的更多信息,请参阅:
http://www.postgresql.org/docs/9.2/static/sql-createextension.html For 有关扩展的更多信息,请参阅:
http://www.postgresql.org/docs/9.2/static/contrib.html其他
某些机器可能需要配置共享内存:
http://www.postgresql.org/docs/9.2/static/kernel-resources.html#SYSVIPC 安装 postgres gem 时,建议使用 ARCHFLAGS: ARCHFLAGS="-arch x86_64" gem install pg要在不使用 sudo 的情况下安装 gem,请参阅 Homebrew wiki。
在登录时启动 postgresql: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents 然后现在加载 postgresql: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 或者,如果你不这样做 想要/需要launchctl,你可以运行: pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start 警告:无法链接 PostgreSQL。取消链接... 错误:
brew link步骤未完成 成功建立了公式,但没有符号链接到 /usr/local 您可以使用 `brew link postgresql' 再试一次 ==> 总结 ???? /usr/local/Cellar/postgresql/9.2.4:2831个文件,38M,4.9分钟构建
解决方案:
我执行这个命令是为了改变文件夹的权限:
sudo chown jeanosorio /usr/local/share/man/man7
然后
brew 链接 postgresql 链接 /usr/local/Cellar/postgresql/9.3.1... 421 创建的符号链接
最后:
sudo ARCHFLAGS="-arch x86_64" gem install pg
获取:pg-0.17.0.gem (100%) 构建原生扩展。这可以 稍等一下……成功安装pg-0.17.0
【问题讨论】:
标签: ruby-on-rails postgresql gem osx-mavericks