背景
Railsのチュートリアルをチュートリアル通り進めると、早速Railsのインストールでエラーが出たので、対処法。
実行したコマンド
gem install rails -v 6.0.3
エラーの内容
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: /Users/tomoki.katsu/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/mimemagic-0.3.10/ext/mimemagic
/Users/tomoki.katsu/.rbenv/versions/2.6.0/bin/ruby -rrubygems /Users/tomoki.katsu/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/rake-12.3.2/exe/rake RUBYARCHDIR\=/Users/tomoki.katsu/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-19/2.6.0/mimemagic-0.3.10 RUBYLIBDIR\=/Users/tomoki.katsu/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-19/2.6.0/mimemagic-0.3.10
rake aborted!
Could not find MIME type database in the following locations: ["/usr/local/share/mime/packages/freedesktop.org.xml", "/opt/homebrew/share/mime/packages/freedesktop.org.xml", "/opt/local/share/mime/packages/freedesktop.org.xml", "/usr/share/mime/packages/freedesktop.org.xml"]
Ensure you have either installed the shared-mime-info package for your distribution, or
obtain a version of freedesktop.org.xml and set FREEDESKTOP_MIME_TYPES_PATH to the location
of that file.
This gem might be installed as a dependency of some bigger package, such as rails, activestorage,
axlsx or cucumber. While most of these packages use the functionality of this gem, some gems have
included this gem by accident. Set USE_FREEDESKTOP_PLACEHOLDER=true if you are certain that you
do not need this gem, and wish to skip the inclusion of freedesktop.org.xml.
The FREEDESKTOP_PLACEHOLDER option is meant as a transitional feature, and will be deprecated in
the next release.
Tasks: TOP => default
(See full trace by running task with --trace)
rake failed, exit code 1
Gem files will remain installed in /Users/tomoki.katsu/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/mimemagic-0.3.10 for inspection.
Results logged to /Users/tomoki.katsu/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-19/2.6.0/mimemagic-0.3.10/gem_make.out
調べてみるとどうやら、shared-mime-info
をインストールするか、インストールするRailsのバージョンを変更する必要があるみたい
解決方法
解決方法は以下2通り
インストールするバージョンを変更
Rails 5.2.5
/ 6.0.3.6
/ 6.1.3.1
をインストールする
shared-mime-info
をインストールする
下記コマンドでshared-mime-info
をインストールします。
brew install shared-mime-info
参考記事