简体   繁体   English

安装pg(0.17.1)时发生错误

[英]error occurred while installing pg (0.17.1)

When I run a bundle on a rails project I seem to be getting the following: 当我在Rails项目上运行捆绑软件时,我似乎得到了以下信息:

Installing pg 0.17.1 with native extensions 使用本地扩展安装pg 0.17.1

Gem::Ext::BuildError: ERROR: Failed to build gem native extension. Gem :: Ext :: BuildError:错误:无法构建gem本机扩展。

 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r 

./siteconf20151024-43303-t81fnp.rb extconf.rb checking for pg_config... yes Using config values from /usr/local/bin/pg_config An error occurred while installing pg (0.17.1), and Bundler cannot continue. ./siteconf20151024-43303-t81fnp.rb extconf.rb正在检查pg_config ...是使用/ usr / local / bin / pg_config中的配置值安装pg(0.17.1)时发生错误,并且Bundler无法继续。 Make sure that gem install pg -v '0.17.1' succeeds before bundling. 捆绑之前,请确保gem install pg -v '0.17.1'成功。

I have visited the following SO questions: 我已经访问了以下SO问题:

Additionally to this I've tried executing the following: 除此之外,我还尝试执行以下命令:

gem install pg

env ARCHFLAGS="-arch x86_64" gem install pg

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

And I keep getting: 而且我不断得到:

ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory. 错误:执行gem时...(Gem :: FilePermissionError)您没有对/Library/Ruby/Gems/2.0.0目录的写权限。

FYI I have rbenv installed too. 仅供参考,我也安装了rbenv。 Also tried a rbenv rehash also and executed the above commands and have had no luck. 还尝试了rbenv rehash并执行了上述命令,但没有运气。 I've also tried uninstalling and reinstalling Postgres and get the same. 我也尝试过卸载并重新安装Postgres并获得相同的结果。 To also be on the safe side i've also ran: 为了安全起见,我还跑过:

  • brew update 酿造更新
  • brew uinstall posgresql > brew install postgresql brew uinstall posgresql> brew安装postgresql
  • updated Xcode 更新的Xcode

Info: 信息:

  • Mac OSx Yosemite 10.10.5 Mac OSx优胜美地10.10.5
  • Postgres v9.4.5 Postgres v9.4.5
  • rbenv v0.4.0 rbenv v0.4.0
  • rbenv global => 2.0.0-p247 rbenv全局=> 2.0.0-p247

I don't know Mac, but I've had this problem on Windows. 我不知道Mac,但是在Windows上遇到了这个问题。

-- -

The issue is here: 问题在这里:

Failed to build gem native extension 无法构建gem本机扩展

When you install a gem, many of the advanced ones actually compile / "build" through the extconf.rb file. 当您安装gem时,许多高级版本实际上都是通过extconf.rb文件进行编译/“构建”的。 I've forgotten the significance of this, but it basically allows the gem to run natively on the OS environment you're using. 我已经忘记了它的重要性,但是它基本上允许gem在您使用的OS环境中本地运行。

In short, the error occurs because your OS does not have access to the "developer headers" the gem requires to compile. 简而言之,发生错误是因为您的操作系统无权访问gem需要编译的“开发人员标头”。

The most common instance of this problem is with the mysql2 gem on Windows , but happens for others too. 此问题的最常见实例是Windows上的mysql2 gem ,但其他情况也是如此。

-- -

What you need is to download PGSQL on your system before attempting to install the gem. 您需要的是尝试安装gem 之前,先在系统上下载PGSQL。

After installing PGSQL, you may need to reference the developer headers with some "switches", but it does not appear to be the case in this instance: 安装PGSQL之后,您可能需要使用一些“开关”来引用开发人员标头,但在这种情况下似乎并非如此:

Installing PG gem on OS X - failure to build native extension 在OS X上安装PG gem-无法构建本机扩展

  1. Install Xcode command line tools (Apple Developer site)
  2. brew uninstall postgresql
  3. brew install postgresql
  4. ARCHFLAGS="-arch x86_64" gem install pg

Maybe this won't work? 也许这行不通吗? I don't know... I know that in Windows, you have to install the binaries before expecting the gem to work. 我不知道...我知道在Windows中,您必须安装二进制文件才能期望gem能够正常工作。

Greetings I hope I can help. 问候,希望能有所帮助。 May I ask how you created your rails project? 请问您是如何创建Rails项目的? Did you simply use: 您是否简单地使用:

rails new *appname*

If so maybe try creating a new rails app like so: 如果是这样,也许尝试创建一个新的Rails应用程序,如下所示:

rails new *appname* -d postgresql

And before you create your database and run migrations/seed, you should go into "config/database.yml" and change the username and password to the postgreSQL user that you've hopefully setup after installing postgreSQL on your machine. 在创建数据库并运行迁移/种子之前,您应该进入“ config / database.yml”并将用户名和密码更改为您希望在计算机上安装了postgreSQL之后设置的postgreSQL用户。

Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM