【问题标题】:Can't Install Rails on Mac OS Catalina无法在 Mac OS Catalina 上安装 Rails
【发布时间】:2021-06-23 16:13:29
【问题描述】:

当我尝试在我的新 Mac 机器上安装 Rails v 6.1.1(仍在 Catalina,而不是 Big Sur)上时,我收到一条错误消息,找不到解决方案

我已经安装了 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

【问题讨论】:

  • 我今天遇到了同样的错误。我会让你知道我发现了什么。今天有新版本的 mimemagic gem。以前的版本被拉了
  • 啊,是的,我看到错误代码中提到了 mimemagic,但不知道它指的是什么。谢谢!

标签: ruby-on-rails ruby linux macos


【解决方案1】:

如果你想让brew 为你安装这个并且你有一段时间没有更新brew,我建议你运行:

HOMEBREW_NO_AUTO_UPDATE=1 brew install shared-mime-info

我只是跑了

brew install shared-mime-info

它更新了一堆我不想让它更新的包,并破坏了我的 ruby​​ 安装。

我也喜欢 spickermann 的解决方案。这似乎是包维护者希望你做的事情。

【讨论】:

  • 感谢 C-RAD!在我试图弄清楚发生了什么的过程中,我同时安装了 rvm 和 rbenv 并且遇到了问题 - 但是一旦我重置为 rbenv 并安装了 shared-mime-info,我就能够安装 Rails!嘘!
  • 这安装了 1000 万个包只是为了...安装一个 gem...
【解决方案2】:

只需在您的计算机上安装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 时,我得到了这个错误代码:错误:执行 gem ... (Errno::EACCES) 权限被拒绝@rb_sysopen - /usr/local/lib/ruby/gems/3.0.0/gems/mimemagic-0.3.10/.gitignore
  • 我认为这是一个单独的问题,但您可以尝试在安装命令前添加 sudo。您可能还想chmod gem 目录stackoverflow.com/questions/38799427/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-11
  • 1970-01-01
  • 2020-02-28
  • 2020-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多