postgresql 安装 pg gem;错误:无法构建 gem 本机扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19539303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing pg gem; ERROR: Failed to build gem native extension
提问by Abramodj
After updating to OS X 10.9 MavericksI tried to start a Rails 3 app, but the connection to the PG database was not working. Checking on PGAdmin III, the database is still there and it works fine. So I tried to reinstall the pg gem:
更新到OS X 10.9 Mavericks 后,我尝试启动 Rails 3 应用程序,但无法连接到 PG 数据库。检查PGAdmin III,数据库仍然存在并且工作正常。所以我尝试重新安装 pg gem:
gem uninstall pg
gem install pg
But the last command doesn't succeed, and gives the following error:
但是最后一个命令没有成功,并给出以下错误:
Building native extensions. This could take a while... ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb checking for pg_config... yes Using config values from
/usr/local/bin/pg_config * 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.
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file.
(RuntimeError) You have to install development tools first. from /Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:461:in
try_link0' from /Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:476:in
try_link' from extconf.rb:39:in `'
构建本机扩展。这可能需要一段时间......错误:安装 pg 时出错:
错误:无法构建 gem 本机扩展。
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb checking for pg_config... yes Using config values from
/usr/local/bin/pg_config * extconf.rb failed *由于某种原因无法创建 Makefile,可能缺少必要的库和/或头文件。检查 mkmf.log 文件以获取更多详细信息。您可能需要配置选项。
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do':编译器无法生成可执行文件。
(RuntimeError) 你必须先安装开发工具。来自 /Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:461:in
try_link0' from /Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:476:in
try_link' 来自 extconf.rb:39:in `'
I guess the problem is related to the Xcode developer tools. I updated Xcode to the latest version, but that didn't solve the problem. Do you know how to fix it?
我猜这个问题与Xcode 开发人员工具有关。我将 Xcode 更新到最新版本,但这并没有解决问题。你知道如何解决吗?
采纳答案by codenamev
回答by schmielson
You're right that the problem is related to the Xcode developer tools. It's not a bad idea to make sure you have all the developer tools installed (as opposed to solely installing gcc as mentioned in the previous answer):
您说得对,问题与 Xcode 开发人员工具有关。确保安装了所有开发人员工具并不是一个坏主意(而不是像前面的答案中提到的那样只安装 gcc):
- Open up Xcode
- In the application menu item "Xcode" select Open Developer Tool > More Developer Tools...
- This takes you to a site with a bunch of software. Go ahead and download and install "Command Line Tools (OS X Mavericks) for Xcode - Late October 2013".
- You will now be able to properly install the gem.
- 打开 Xcode
- 在应用程序菜单项“Xcode”中选择 Open Developer Tool > More Developer Tools...
- 这会将您带到一个包含大量软件的站点。继续下载并安装“适用于 Xcode 的命令行工具 (OS X Mavericks) - 2013 年 10 月下旬”。
- 您现在将能够正确安装 gem。
For anyone else coming to this issue off of a fresh install of the Postgres 9.3.0 app on Mac OS X Mavericks (i.e. you're not using homebrew for your Postgres installation) you may notice that even though you can build the pg gem you cannot run rake because of a dylib issue:
对于在 Mac OS X Mavericks 上全新安装 Postgres 9.3.0 应用程序(即您没有使用自制软件安装 Postgres)而遇到此问题的任何其他人,您可能会注意到,即使您可以构建 pg gem由于 dylib 问题,无法运行 rake:
rake aborted!
dlopen(/Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: @loader_path/../lib/libpq.5.dylib
Referenced from: /Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle
Reason: image not found - /Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle
Unfortunately this is a problem with the current release version of 9.3.0 of Postgres. Winding back to a previous version will fix it for you:
不幸的是,这是 Postgres 9.3.0 当前发行版的一个问题。回退到以前的版本将为您修复它:
- uninstall the pg gem:
gem uninstall pg
- delete your 9.3.0 Postgres app by dragging it to the trash and emptying the trash
- install version 9.2.2.0 of the Postgres app here: http://postgres-app.s3.amazonaws.com/PostgresApp-9-2-2-0.zip
- reinstall the pg gem:
gem install pg
- 卸载 pg gem:
gem uninstall pg
- 通过将 9.3.0 Postgres 应用程序拖到垃圾箱并清空垃圾箱来删除它
- 在此处安装 Postgres 应用程序的 9.2.2.0 版:http://postgres-app.s3.amazonaws.com/PostgresApp-9-2-2-0.zip
- 重新安装 pg gem:
gem install pg
*Thanks to the commentby jhiro009 on this threadfor pointing me in the right direction on this last Postgres app part of the issue although the 9.2.4.3 version that he mentioned didn't work for me.
*感谢jhiro009 在此线程上的评论,尽管他提到的 9.2.4.3 版本对我不起作用,但他在问题的最后一个 Postgres 应用程序部分为我指出了正确的方向。
回答by guapolo
On OS X Mavericks
在 OS X Mavericks 上
sudo ln -s /usr/bin/llvm-gcc /usr/bin/gcc-4.2
gem uninstall pg; gem install pg;
works with homebrew Postgresql (9.3.1) installation and Apple Command Line Tools installed (pg 0.17.0).
适用于自制 Postgresql (9.3.1) 安装和 Apple 命令行工具安装 (pg 0.17.0)。
回答by iceui2
None of the previous solutions worked for me (I just upgraded to Mavericks and updated XCode). Instead, I installed Postgress.app. and called
以前的解决方案都不适合我(我刚刚升级到 Mavericks 并更新了 XCode)。相反,我安装了Postgress.app。并叫
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
回答by Yuri
None of the solutions worked for me, and I didn't want to use MacPorts. Try and download the Postgres Appand put it into the Application directory.
没有一个解决方案对我有用,我不想使用 MacPorts。尝试下载Postgres 应用程序并将其放入应用程序目录。
Then, specify the location of newly downloaded pg_config
, which resides inside the app:
然后,指定pg_config
驻留在应用程序内的新下载的位置:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
If you run in to missing headers problem, try specifying the include
directory of the app:
如果您遇到缺少标题的问题,请尝试指定include
应用程序的目录:
gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/MacOS/include/'
回答by Don Sullivan
If you are looking for just a quick fix, add the following to your database.yml file:
如果您只想快速修复,请将以下内容添加到您的 database.yml 文件中:
host: localhost
I had the exact problem, added that line, and now all is well.
我遇到了确切的问题,添加了该行,现在一切都很好。
回答by purpletonic
I had luck following this post from the guys at New-Bamboo:
我很幸运地关注了 New-Bamboo 员工的这篇文章:
3 Quick Tips for Coding with OS X 10.9 Mavericks
使用 OS X 10.9 Mavericks 进行编码的 3 个快速提示
After installing the xcode dev tools, the third step sorted everything out:
安装好xcode开发工具后,第三步把所有东西都整理好了:
brew tap homebrew/versions && brew install apple-gcc42
brew link --force apple-gcc42
ln -nsf $(which gcc-4.2) /usr/bin/gcc-4.2
回答by Bernardo
I had this problem the first time I tried to install pg. Through various trials and errors I found something that worked. Thankfully, my notes also worked when Mavericks broke everything.
我第一次尝试安装 pg 时遇到了这个问题。通过各种试验和错误,我发现了一些有效的方法。值得庆幸的是,当小牛队打破一切时,我的笔记也奏效了。
Hope this helps:
希望这可以帮助:
Do not do any brewing.
不要做任何酿造。
download the enterpriseDB one-click installer, mount and run. If it doesn't work, run it through the command line (unattended mode) and it will change the memory settings. Restart, run again.
下载enterpriseDB一键安装程序,挂载运行。如果它不起作用,请通过命令行(无人值守模式)运行它,它将更改内存设置。重新启动,再次运行。
Makes a user called postgres with the password you supply. Also installs pgadmin III.
使用您提供的密码创建一个名为 postgres 的用户。还安装 pgadmin III。
run this in app directory:
在应用程序目录中运行它:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-include=/Library/PostgreSQL/9.2/include/ --with-pg-lib=/Library/PostgreSQL/9.2 sudo env ARCHFLAGS='-arch i386' gem install pg/lib/
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-include=/Library/PostgreSQL/9.2/include/ --with-pg-lib=/Library/PostgreSQL/9.2 sudo env ARCHFLAGS='- arch i386' gem 安装 pg/lib/
Open pgadmin3 and create a user and password for rails, then add it to config.
打开 pgadmin3 并为 rails 创建用户和密码,然后将其添加到 config.xml 中。
psql [database_name] # to check on your db. Or use pgadmin III
psql [database_name] # 检查你的数据库。或者使用 pgadmin III