1. brew update error
(i) 问题出现及现象描述
昨天换了台电脑,有些软件需要重新安装或更新一下,遇到了下面的问题
cv@xys-MacBook-Pro ~ % brew update
touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/.git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD: Permission denied
error: cannot open .git/FETCH_HEAD: Permission denied
/usr/local/Homebrew/Library/Homebrew/cmd/update.sh: line 522: /usr/local/Homebrew/.git/UPDATE_FAILED: Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
error: could not lock config file .git/config: Permission denied
Already up-to-date.
(ii) 解决方案
在StackOverflow上找到了一个类似的问题,用高赞的回答解决了这个问题。
直接通过改变 /usr/local 的所属用户进而解决权限问题。
不同的版本使用的指令略有不同,如果是 macOS High Sierra 或更高版本的系统的用户,使用下面的指令可以修改所属权,
~$ sudo chown -R $(whoami) $(brew --prefix)/*
如果是 macOS Sierra 或更低版本的系统的用户,使用下面的指令
~$ sudo chown -R $(whoami) /usr/local
查看本机系统版本信息,可以通过单击左上角苹果 Logo ==> 关于本机,就能看到系统版本号及其名称。版本号之间的高低可以通过WikiPedia上面记载的版本与名称对应列表来查询。
Public Beta: "Kodiak", Released on September 13, 2000
Version 10.0: "Cheetah", Released on March 24, 2001
Version 10.1: "Puma", Released on September 25, 2001
Version 10.2: "Jaguar", Released on August 23, 2002
Version 10.3: "Panther", Released on October 24, 2003
Version 10.4: "Tiger", Released on April 29, 2005
Version 10.5: "Leopard", Released on October 26, 2007
Version 10.6: "Snow Leopard", Released on August 28, 2009
Version 10.7: "Lion", Released on July 20, 2011
Version 10.8: "Mountain Lion", Released on July 25, 2012
Version 10.9: "Mavericks", Released on October 22, 2013
Version 10.10: "Yosemite", Released on October 16, 2014
Version 10.11: "El Capitan", Released on June 8, 2015
Version 10.12: "Sierra", Released on June 13, 2016
Version 10.13: "High Sierra", Released on June 5, 2017
Version 10.14: "Mojave", Released on June 4, 2018
Version 10.15: "Catalina", Released on June 3, 2019
Version 11: "Big Sur", Released on June 22, 2020
2. brew update "Fetching homebrew-cask failed!"
(i) 问题描述
尽管权限问题用上述方法解决了,但后续执行时又遇到了一点问题,这次是主要是Homebrew的其中两个组成部分homebrew-cask
和homebrew-core
引起的,出现了如下所示的 "Fetching failed" 错误。
cv@xys-MBP ~ % brew update
Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed!
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
Updated 2 taps (homebrew/cask and caskroom/cask).
(ii) 解决方案
尝试了一些方法都没解决,最后选择重新安装 Homebrew,毕竟没有什么问题是重装不能解决的,如过有,就连系统一起重装...话说回来,重装之后确实没有问题了(\汗)。
首先自然是卸载已有的安装版本,指令是 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
,结果如下。
cv@xys-MBP ~ % /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Warning: The Ruby Homebrew uninstaller is now deprecated and has been rewritten in
Bash. Please migrate to the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443
cv@xys-MBP ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)
接着当然是安装新版本,指令是/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
,结果如下,中间有一次需要根据自己的需求选择源并输入 root 密码。
cv@xys-MBP ~ % /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
开始执行Brew自动安装程序
[[email protected]]
['2021-05-20 17:53:17']['11.3']
https://zhuanlan.zhihu.com/p/111014448
请选择一个下载镜像,例如中科大,输入1回车。
源有时候不稳定,如果git克隆报错重新运行脚本选择源。cask非必须,有部分人需要。
1、中科大下载源 2、清华大学下载源 3、北京外国语大学下载源 4、腾讯下载源(不推荐) 5、阿里巴巴下载源(不推荐 缺少cask源)
请输入序号:
我选择了中科大下载源,输入 1 回车即可。
你选择了中国科学技术大学下载源
!!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
->是否现在开始执行脚本(N/Y)
是否执行,选择是,输入 Y 回车继续。接着输入密码后正常情况下就能一直运行到最后了,如果中间断了根据提示进行相应的操作即可。
--> 脚本开始执行
Mac os设置开机密码方法:
(设置开机密码:在左上角苹果图标->系统偏好设置->用户与群组->更改密码)
(如果提示This incident will be reported. 在用户与群组中查看是否管理员)
==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
请输入开机密码,输入过程不显示,输入完后回车
开始执行
---备份要删除的/usr/local/Homebrew到系统桌面....
---/usr/local/Homebrew 备份完成
-> 创建文件夹 /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew
此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown cv /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
git version 2.20.1
下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
==> 克隆Homebrew基本文件
未发现Git代理(属于正常状态)
Cloning into '/usr/local/Homebrew'...
remote: Enumerating objects: 191263, done.
remote: Total 191263 (delta 0), reused 0 (delta 0) | 10.55 MiB/s
Receiving objects: 100% (191263/191263), 48.84 MiB | 10.64 MiB/s, done.
Resolving deltas: 100% (142769/142769), done.
此步骤成功
--创建Brew所需要的目录
运行代码 ==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin/brew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin/brew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/sbin /usr/local/Caskroom
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/sbin /usr/local/Caskroom
运行代码 ==> /usr/bin/sudo /usr/sbin/chown cv /usr/local/sbin /usr/local/Caskroom
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/sbin /usr/local/Caskroom
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R cv:admin /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /Users/cv/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/cv/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R cv /Users/cv/Library/Caches/Homebrew
--依赖目录脚本运行完成
==> 创建brew的替身
==> 克隆Homebrew Core
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 960954, done.
remote: Total 960954 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (960954/960954), 380.33 MiB | 10.66 MiB/s, done.
Resolving deltas: 100% (660866/660866), done.
Checking out files: 100% (5914/5914), done.
此步骤成功
==> 克隆Homebrew Cask 图形化软件
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 624249, done.
remote: Total 624249 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (624249/624249), 260.95 MiB | 9.69 MiB/s, done.
Resolving deltas: 100% (445746/445746), done.
此步骤成功
==> 克隆Homebrew services 管理服务的启停
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 1141, done.
remote: Counting objects: 100% (1141/1141), done.
remote: Compressing objects: 100% (495/495), done.
remote: Total 1141 (delta 484), reused 1141 (delta 484), pack-reused 0
Receiving objects: 100% (1141/1141), 331.50 KiB | 330.00 KiB/s, done.
Resolving deltas: 100% (484/484), done.
此步骤成功
==> 配置国内镜像源HOMEBREW BOTTLE
sed: /Users/cv/.zprofile: No such file or directory
环境变量写入->/Users/cv/.zprofile
此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown cv /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
==> 安装完成,brew版本
Homebrew 3.1.8-50-g76c4767-dirty
Homebrew/homebrew-core (git revision 832bb8b966; last commit 2021-05-20)
Homebrew/homebrew-cask (git revision f397055044; last commit 2021-05-20)
Brew前期配置成功
电脑系统版本:11.3
All user-space services OK, nothing cleaned...
==> brew update-reset
==> Fetching /usr/local/Homebrew...
==> Resetting /usr/local/Homebrew...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
Checking out files: 100% (3977/3977), done.
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Checking out files: 100% (5659/5659), done.
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services...
==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
Brew自动安装程序运行完成
国内地址已经配置完成
桌面的Old_Homebrew文件夹,大致看看没有你需要的可以删除。
初步介绍几个brew命令
本地软件库列表:brew ls
查找软件:brew search google(其中google替换为要查找的关键字)
查看brew版本:brew -v 更新brew版本:brew update
安装cask软件:brew install --cask firefox 把firefox换成你要安装的
欢迎右键点击下方地址-打开URL 来给点个赞
https://zhuanlan.zhihu.com/p/111014448
重启终端 或者 运行 source /Users/cv/.zprofile 否则可能无法使用
安装完成后按照提示运行 source 命令
cv@xys-MBP ~ % source ~/.zprofile
至此重装过程结束,开始正常使用 Homebrew。
(全文完)
参考资料
[1] brew update fails with “Permission denied” error (https://stackoverflow.com/questions/50267510/brew-update-fails-with-permission-denied-error/50268978)
[2] macOS version history (https://en.wikipedia.org/wiki/MacOS_version_history)
[3] mac下Homebrew安装Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask failed报错解决方法 (http://www.cxyzjd.com/article/Jiangzhiqi4551/116174524)
[4] Mac 下 brew 切换为国内源 (https://cloud.tencent.com/developer/article/1614039)
附国内一些开源镜像网址
-
中国科学技术大学开源软件镜像(目前中国大陆高校访问量最大、收录最全的开源软件镜像,由中国科学技术大学网络信息中心提供支持)
https://mirrors.ustc.edu.cn/ -
清华大学开源软件镜像(由清华大学信息化技术中心支持创办,由清华大学 TUNA 协会运行维护)
https://mirrors.tuna.tsinghua.edu.cn/ -
北京外国语大学开源软件镜像(由北外信息技术中心支持创办,由清华大学 TUNA 协会运行维护)
https://mirrors.bfsu.edu.cn/ -
阿里云镜像源(由阿里巴巴技术保障部基础系统组提供支持)
https://mirrors.aliyun.com/ -
网易开源镜像
https://mirrors.163.com/