mimemagic install error: "Could not find MIME type database in the following locations..." on Windows

mimemagic install error: "Could not find MIME type database in the following locations..." on Windows

在 Rails 项目的 Ruby 中尝试安装 mimemagic 0.3.10 时,我 运行 遇到以下错误。请注意,它在 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.

请记住,我正在自己回答这个问题,因为我找到了解决方案,并想与可能 运行 遇到相同问题的任何人分享。

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

的文件

然后复制在此link中找到的文件内容并粘贴到刚刚创建的文件中。

最后,设置FREEDESKTOP_MIME_TYPES_PATH环境变量

Unix 终端:

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

命令提示符:

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