問題:ruby-filemagic gem インストールの失敗
入力
gem install ruby-filemagic -v '0.7.2'
出力
ERROR: Error installing ruby-filemagic:
ERROR: Failed to build gem native extension.
current directory: /home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/ruby-filemagic-0.7.2/ext/filemagic
/home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/bin/ruby -r ./siteconf20190315-389-smjtdo.rb extconf.rb
checking for -lgnurx... no
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=/home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/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-gnurx-dir
--without-gnurx-dir
--with-gnurx-include
--without-gnurx-include=${gnurx-dir}/include
--with-gnurx-lib
--without-gnurx-lib=${gnurx-dir}/lib
--with-gnurxlib
--without-gnurxlib
--with-magiclib
--without-magiclib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/ruby-filemagic-0.7.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/ruby-filemagic-0.7.2 for inspection.
Results logged to /home/【ユーザー名】/.anyenv/envs/rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/ruby-filemagic-0.7.2/gem_make.out
環境
本記事における環境
- Windows Subsystem for Linux (WSL)
- Ubuntu 18.04 LTS
- anyenv
- rbenv 1.1.1-39-g59785f6
- ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux]
- rbenv 1.1.1-39-g59785f6
Ubuntu(Debian系)以外の環境の場合
補足に記述。
原因:FileMagicライブラリ
native extension用のFileMagicライブラリが未インストール。
解決方法
sudo apt install libmagic-dev
gem install ruby-filemagic -v '0.7.2'
補足
CentOS等Fedora系、Gentoo Linux、OS X(Mac)については以下の通り。
Debian系におけるsudo apt install libmagic-dev
コマンドを下記のものにそれぞれ置き換える。
Fedora系
sudo yum install file-devel
Gentoo
sudo emerge sys-libs
sudo emerge libmagic
OS X
brew install libmagic