LoginSignup
13
10

More than 5 years have passed since last update.

ruby-filemagic -v 0.6.1 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. の解決方法

Last updated at Posted at 2017-03-02

備忘録です。
bundle install が通らずRubyのバージョンを変えてやってみたのですが、あと一歩のところでエラーが出ました。
Rubyのバージョンは2.3.1、bundlerのバージョンはRuby2.3.1に対応するバージョンです。

$ bundle install

Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies................................
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.2
Using minitest 5.5.0
Using thread_safe 0.3.4
Using builder 3.2.2
Using erubis 2.7.0
Using rack 1.5.2
Using mime-types 2.4.3
Using sass 3.2.19
Using thor 0.19.1
Using coffee-script-source 1.8.0
Using execjs 2.2.2
Using formtastic_i18n 0.6.0
Using arel 5.0.1.20140414130214
Using hike 1.2.3
Using multi_json 1.10.1
Using tilt 1.4.1
Using addressable 2.3.8
Using ast 2.3.0
Using awesome_print 1.2.0
Using jmespath 1.3.1
Using bcrypt 3.1.9
Using coderay 1.1.0
Using debug_inspector 0.0.2
Using bundler 1.13.6
Using columnize 0.9.0
Using debugger-linecache 1.2.0
Using slop 3.6.0
Using cancancan 1.13.1
Using chunky_png 1.3.4
Using orm_adapter 0.5.0
Using multipart-post 2.0.0
Using elasticsearch-dsl 0.1.4
Using hashie 3.4.6
Using libv8 3.16.14.15
Using method_source 0.8.2
Using mysql2 0.3.18
Using powerpack 0.1.1
Using yard 0.8.7.6
Using rainbow 2.1.0
Using ref 1.0.5
Using ruby-progressbar 1.8.1
Using unicode-display_width 1.1.1
Installing ruby-filemagic 0.6.1 with native extensions
Using rubyzip 1.1.7
Using spring 1.2.0
Using sqlite3 1.3.10
Using uuidtools 2.1.5
Using rdoc 4.2.0
Using tzinfo 1.2.2
Using rack-test 0.6.2
Using warden 1.2.3
Using mail 2.6.3
Using bourbon 3.2.4
Using coffee-script 2.3.0
Using uglifier 2.6.0
Using elasticsearch-api 5.0.0
Using sprockets 2.12.3
Using fastimage 1.7.0
Using parser 2.3.1.4
Using aws-sdk-core 2.3.19
Using better_errors 2.0.0
Using binding_of_caller 0.7.2
Using byebug 3.5.1
Using rqrcode 0.7.0
Using faraday 0.9.2
Using pry 0.10.1
Using therubyracer 0.12.2
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/fndm40/JinsPaintWEBAdmin/jinspaintwebadmin/web-admin/vendor/bundle/ruby/2.3.0/gems/ruby-filemagic-0.6.1/ext/filemagic
/Users/fndm40/.rbenv/versions/2.3.1/bin/ruby -r
./siteconf20170302-11345-1879bea.rb extconf.rb
checking for magic_open() in -lmagic... no
*** ERROR: missing required library to compile this module
*** 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
    --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/fndm40/.rbenv/versions/2.3.1/bin/$(RUBY_BASE_NAME)
    --with-magic-dir
    --without-magic-dir
    --with-magic-include
    --without-magic-include=${magic-dir}/include
    --with-magic-lib
    --without-magic-lib=${magic-dir}/lib
    --with-magiclib
    --without-magiclib

To see why this extension failed to compile, please check the mkmf.log which
can be found here:

/Users/fndm40/JinsPaintWEBAdmin/jinspaintwebadmin/web-admin/vendor/bundle/ruby/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/ruby-filemagic-0.6.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/fndm40/JinsPaintWEBAdmin/jinspaintwebadmin/web-admin/vendor/bundle/ruby/2.3.0/gems/ruby-filemagic-0.6.1
for inspection.
Results logged to
/Users/fndm40/JinsPaintWEBAdmin/jinspaintwebadmin/web-admin/vendor/bundle/ruby/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/ruby-filemagic-0.6.1/gem_make.out

An error occurred while installing ruby-filemagic (0.6.1), and
Bundler cannot continue.
Make sure that `gem install ruby-filemagic -v '0.6.1'` succeeds before
bundling.

gemの ruby-filemagic に問題があるようです。
ちなみに gem install ruby-filemagic -v '0.6.1' をやっても同じようなエラーが出ました。

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.

と書いているので mkmf.logファイルを探して参照してみます。

$ find ~/.rbenv | grep ruby-filemagic | grep mkmf.log

/Users/fndm40/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/ruby-filemagic-0.6.1/mkmf.log

場所を特定したのでvimでファイルを開きます。

$ vim /Users/fndm40/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/ruby-filemagic-0.6.1/mkmf.log

中身を見ましたが、全く意味がわからない。
中身はC言語で書かれているのですが、エラーがいろんなところに出ている。
困った。
そもそも gem install ruby-filemagic でつまずいてる人がいないか調べてみたら、いました!

$ brew install libmagic

を行い

$ gem install ruby-filemagic -v '0.6.1'
$ bundle install

をやったら解決。
やっと開発環境を整えられる…。

13
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
10