错误:无法在OSX 10.9.4上构建gem本机扩展(bundle install)

时间:2014-12-02 18:27:50

标签: ruby-on-rails ruby macos

运行:OSX 10.9.4,Ruby 2.1.5,Rails 4.1.8(但是,项目子文件夹中的4.1.6)

在项目子文件夹中安装gem时遇到问题。在jquery-rails 3.1.2中,bundle install似乎失败了。无法在Stackoverflow上找到解决方案,所以询问是否有人知道如何补救?

这是输出:

Macintosh:~ asanchez$ cd Projects
Macintosh:Projects asanchez$ ls
rails-2
Macintosh:Projects asanchez$ cd rails-2
Macintosh:rails-2 asanchez$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Installing rake 10.3.2
Using i18n 0.6.11
Using json 1.8.1
Using minitest 5.4.3
Using thread_safe 0.3.4
Using tzinfo 1.2.2
Installing activesupport 4.1.6
Using builder 3.2.2
Using erubis 2.7.0
Installing actionview 4.1.6
Using rack 1.5.2
Using rack-test 0.6.2
Installing actionpack 4.1.6
Using mime-types 2.4.3
Using mail 2.6.3
Installing actionmailer 4.1.6
Installing activemodel 4.1.6
Using arel 5.0.1.20140414130214
Installing activerecord 4.1.6
Installing sass 3.2.19
Installing bootstrap-sass 3.3.1.0
Installing coffee-script-source 1.8.0
Installing execjs 2.2.2
Installing coffee-script 2.3.0
Using thor 0.19.1
Installing railties 4.1.6
Installing coffee-rails 4.0.1
Installing font-awesome-sass 4.2.2
Using hike 1.2.3
Using multi_json 1.10.1
Installing jbuilder 2.2.5
Installing jquery-rails 3.1.2

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/asanchez/.rvm/rubies/ruby-2.1.5/bin/ruby -r ./siteconf20141202-33892-1jyqcz2.rb extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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/asanchez/.rvm/rubies/ruby-2.1.5/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}/lib

extconf failed, exit code 1

Gem files will remain installed in /Users/asanchez/.rvm/gems/ruby-2.1.5/gems/pg-0.17.1 for inspection.
Results logged to /Users/asanchez/.rvm/gems/ruby-2.1.5/extensions/x86_64-darwin-13/2.1.0/pg-0.17.1/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

而且,这是我检查Rails版本时的输出:

Macintosh:rails-2 asanchez$ rails --version
Rails 4.1.6
Macintosh:rails-2 asanchez$ cd ..
Macintosh:Projects asanchez$ rails --version
Rails 4.1.8

2 个答案:

答案 0 :(得分:1)

这个问题在Mac上很常见(至少根据我的经验)。它的长短是因为它找不到系统上PosgreSQL安装的配置文件。

当我第一次添加pg gem时(即安装升级版的Ruby之后),我使用以下内容:

gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config

请注意,我使用Postgres Mac app,因为我觉得它比手动或通过Homebrew安装PG容易得多。当前版本的应用程序名称中不再包含93。

无论你如何安装PostgreSQL,你都需要将rubygems指向PG的正确配置文件,否则它将无法安装。

另外,请勿通过Bundler安装此设备。这从来没有对我有用。我总是不得不使用gem install命令。然后,当我运行bundle xxxxx时,它永远不会失败。

希望有所帮助!

答案 1 :(得分:1)

看起来它实际上在pg gem(postgres)失败了。

您必须首次手动安装postgres,因此请尝试单独运行gem install postgres。

另一种选择,如果这会减慢你的速度,就是打开你的gemfile并将postgres放入生产组。您可以在习惯使用rails时使用sqlite 3,然后再担心PG。要将它放在自己的组中,打开你的Gemfile并将pg放在它自己的组中:

group :assets do
  gem 'pg'
end

并运行"bundle install --without-production"

或者您可以运行bundle install --without-pg,但请注意,这两种方式都有点笨拙。如果您想快速入门,请使用它们,然后再担心您的环境。