2014-12-02 117 views
0

運行:OSX 10.9.4,Ruby 2.1.5,Rails 4.1.8(但項目子文件夾中爲4.1.6)錯誤:無法在OSX上創建gem本機擴展(捆綁安裝)10.9.4

我在項目子文件夾中安裝gem存在問題。捆綁安裝似乎失敗在jquery-rails 3.1.2。在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: 
 
\t --with-opt-dir 
 
\t --with-opt-include 
 
\t --without-opt-include=${opt-dir}/include 
 
\t --with-opt-lib 
 
\t --without-opt-lib=${opt-dir}/lib 
 
\t --with-make-prog 
 
\t --without-make-prog 
 
\t --srcdir=. 
 
\t --curdir 
 
\t --ruby=/Users/asanchez/.rvm/rubies/ruby-2.1.5/bin/ruby 
 
\t --with-pg 
 
\t --without-pg 
 
\t --with-pg-config 
 
\t --without-pg-config 
 
\t --with-pg_config 
 
\t --without-pg_config 
 
\t --with-pg-dir 
 
\t --without-pg-dir 
 
\t --with-pg-include 
 
\t --without-pg-include=${pg-dir}/include 
 
\t --with-pg-lib 
 
\t --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

回答

1

的問題是Mac上常見的問題(至少在我的經驗中)。總而言之,它無法在您的系統上找到PosgreSQL安裝的配置文件。

當我添加了pg寶石的第一次(即安裝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

看起來它實際上在pg gem(postgres)失敗。

您必須首次手動安裝postgres,因此請嘗試單獨運行gem install postgres。

另一個選擇,如果這會讓你放慢速度,那就是打開你的gemfile並把postgres放到生產組中。你可以在習慣rails時使用sqlite 3,然後再擔心PG。把它放在自己的組中,打開您的Gemfile,並把皮克在自己的組:

group :assets do 
    gem 'pg' 
end 

和運行"bundle install --without-production"

另外,您可以運行bundle install --without-pg,但請注意,這兩種方式都是一種哈克。如果您希望快速入門,請使用它們,然後再擔心您的環境。

相關問題