问题描述
当执行 brew 命令时,产生如下错误:
# brew doctor ==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz Already downloaded: /Users/pengfeiwang/Library/Caches/Homebrew/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz ==> Pouring portable-ruby-2.6.3_2.yosemite.bottle.tar.gz portable-ruby/2.6.3_2/: Can't create 'portable-ruby/2.6.3_2' portable-ruby/2.6.3_2/.brew/: Failed to create dir 'portable-ruby/2.6.3_2' .... portable-ruby/2.6.3_2/bin/rdoc: Failed to create dir 'portable-ruby/2.6.3_2' portable-ruby/2.6.3_2/bin/ri: Failed to create dir 'portable-ruby/2.6.3_2' portable-ruby/2.6.3_2/bin/ruby: Failed to create dir 'portable-ruby/2.6.3_2' portable-ruby/2.6.3_2/.brew/portable-ruby.rb: Failed to create dir 'portable-ruby/2.6.3_2' tar: Error exit delayed from previous errors. Error: Failed to install ruby 2.6.3_2! Error: Failed to upgrade Homebrew Portable Ruby!
该笔记将记录:如何解决该问题,以及注意事项。
问题原因
在 Google 后,我们发现导致该问题的原因有很多,但是究其根本,正如错误信息的提示:Failed to create dir 'portable-ruby/2.6.3_2'。因此,我们尝试查找 portable-ruby/2.6.3_2 无法写入的原因。
Homebrew 的安装目录为 /usr/local/Homebrew ,而 portable-ruby/ 在 /usr/local/Homebrew/Library/Homebrew/vendor/ 中,我们发现 vendor 目录属于其他用户。在我们的场景中,该主机的其他用户以前已经安装过 Homebrew 工具。当我们进行安装时,由于权限问题导致安装失败。
解决方案
针对我们的问题,修改 /user/local/Homebrew 权限即可。但是我们发现 /usr/local 的很多文件都属于其他用户,所以我们进行全部修改:
# sudo chown -R -v $(whoami): /usr/local/*
将 /usr/local 下的全部文件都修改为当前用户和当前用户所属的组。
参考文献
Failed to install Homebrew Portable Ruby (and your system version is too old) - Stack Overflow