首页 > 解决方案 > mimemagic 安装错误:“在以下位置找不到 MIME 类型数据库...”在 Windows 上

问题描述

尝试mimemagic 0.3.10在 Ruby on Rails 项目中安装时遇到以下错误。请注意,它是在 Windows 环境中运行的。这是最相关的错误堆栈跟踪:

Fetching mimemagic 0.3.10
Installing mimemagic 0.3.10 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/Ruby26/lib/ruby/gems/2.6.0/gems/mimemagic-0.3.10/ext/mimemagic
C:/Ruby26/bin/ruby.exe -rrubygems
C:/Ruby26/lib/ruby/gems/2.6.0/gems/rake-13.0.6/exe/rake
RUBYARCHDIR\=C:/Ruby26/lib/ruby/gems/2.6.0/extensions/x86-mingw32/2.6.0/mimemagic-0.3.10    
RUBYLIBDIR\=C:/Ruby26/lib/ruby/gems/2.6.0/extensions/x86-mingw32/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.

请记住,我自己在回答这个问题,因为我找到了解决方案,并希望与可能遇到相同问题的其他人分享。

标签: ruby-on-railsrubyrubygemsbundlemime

解决方案


首先,创建一个名为freedesktop.org.xml.

然后复制此链接中找到的文件内容并将其粘贴到刚刚创建的文件中。

最后,设置FREEDESKTOP_MIME_TYPES_PATH环境变量

Unix 终端:

export FREEDESKTOP_MIME_TYPES_PATH=/path/to/freedesktop.org.xml

命令提示符:

setx FREEDESKTOP_FILE_PATH "\path\to\freedesktop.org.xml" 

推荐阅读