无法在Mac OS Catalina上安装Rails

23

我在尝试在我的新Mac机器上安装Rails v 6.1.1时收到一个错误消息,但无法找到解决方案。

我已经安装了rbenv和Homebrew,并更新到最新版本的Ruby(3.0.0)。当我输出which ruby时,我得到:/usr/local/opt/ruby/bin/ruby

这是我在终端上运行gem install rails -v 6.1.1时看到的错误代码(使用sudo安装时出现相同错误):

 Building native extensions. This could take a while...
 ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

 current directory: /usr/local/lib/ruby/gems/3.0.0/gems/mimemagic-0.3.10/ext/mimemagic
 /usr/local/opt/ruby/bin/ruby -I/usr/local/lib/ruby/site_ruby/3.0.0 -rrubygems /usr/local/Cellar/ruby/3.0.0_1/lib/ruby/gems/3.0.0/gems/rake-13.0.3/exe/rake RUBYARCHDIR\=/usr/local/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-19/3.0.0/mimemagic-0.3.10 RUBYLIBDIR\=/usr/local/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-19/3.0.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.
 /usr/local/lib/ruby/gems/3.0.0/gems/mimemagic-0.3.10/ext/mimemagic/Rakefile:15:in `locate_mime_database'
 /usr/local/lib/ruby/gems/3.0.0/gems/mimemagic-0.3.10/ext/mimemagic/Rakefile:39:in `block in <top (required)>'
 Tasks: TOP => default
 (See full trace by running task with --trace)

 rake failed, exit code 1

 Gem files will remain installed in /usr/local/lib/ruby/gems/3.0.0/gems/mimemagic-0.3.10 for inspection.
 Results logged to /usr/local/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-19/3.0.0/mimemagic-0.3.10/gem_make.out

1
今天我也遇到了同样的错误。我会告诉你我找到了什么。今天有新版本的mimemagic gem发布了。之前的版本已经被撤下了。 - C-RAD
啊,是啊,我在错误代码中看到了对mimemagic的提及,但不知道是指什么。谢谢! - Laura Thorson
这里的解决方案对我有用... https://dev59.com/b1EG5IYBdhLWcg3wQoVw - Hez
2个回答

48

如果你想让brew为你安装此软件,并且你已经有一段时间没有更新brew了,我建议运行以下命令:

HOMEBREW_NO_AUTO_UPDATE=1 brew install shared-mime-info

我只是运行了一下

brew install shared-mime-info

它更新了一堆我不想要的软件包并破坏了我的 Ruby 安装。

我也喜欢 spickermann 的解决方案。这似乎是软件包维护者希望你采取的措施。


1
谢谢C-RAD!在我试图弄清楚发生了什么事情时,我安装了rvm和rbenv并遇到了问题 - 但是一旦我重置为rbenv并安装了shared-mime-info,我就能够安装Rails!万岁! - Laura Thorson
1
这将安装一千万个软件包,只为了安装一个 gem... - jedi

12

只需在计算机上安装shared-mime-info即可。根据mimemagic gem文档。

您需要一个Freedesktop.org shared-mime-info数据库的副本可用。如果您使用的是Linux,则可以通过软件包管理器获得它,并且当安装gem时,它可能位于被查找位置。

macOS用户可以使用Homebrew安装数据库:
brew install shared-mime-info

如果无法使用软件包管理器,则可以通过从Debian软件包中提取它来获取所需文件的副本。这个过程也适用于Windows机器。[...]

或者

您可能希望考虑安装Rails 6.1.3.1(而不是在命令中使用6.1.1)。该版本是为了修复您正在遇到的mimemagic问题而发布的——只是几个小时前。


所以我运行了brew install shared-mime-info,然后当我尝试安装rails时,我得到了这个错误代码:ERROR: While executing gem ... (Errno::EACCES) Permission denied @ rb_sysopen - /usr/local/lib/ruby/gems/3.0.0/gems/mimemagic-0.3.10/.gitignore - Laura Thorson
1
我认为那是一个单独的问题,但你可以尝试在安装命令前加上 sudo。你可能还想要对 gem 目录进行 chmod https://dev59.com/SJnga4cB1Zd3GeqPa5qP - C-RAD

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接