解决Mac下安装Homebrew慢的问题
一、方法一
国内安装Homebrew很慢,可以使用下面的方法:
1curl -fsSL https://gitee.com/xueweihan/codes/vfrgh7z8qcjlx1ubwt6nk71/raw\?blob_name\=brew_install.sh >> brew_install
先把安装文件保存到brew_install,然后修改其中的仓库地址,打开 brew_install 文件,把 BREW_REPO后面引号内的地址改为:
https://mirrors.ustc.edu.cn/brew.git
或者
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
如果有CORE_TAP_REPO,则把引号内的地址改为:
https://mirrors.ustc.edu.cn/homebrew-core.git
或者
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
如果没有CORE_TAP_REPO也不用新增。 执行下面的命令开始安装:
1/usr/bin/ruby brew_install
安装到显示:
1==> Tapping homebrew/core
2Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
时,可能会比较慢了,此时中断安装。手动执行:
1git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
上面的git地址可以使用前面CORE_TAP_REPO的两个地址中任意一个。
然后再把homebrew-core的地址也改为国内的镜像地址:
1cd $(brew --repo)
2git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
3cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
4git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
或者:
1git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
2git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
3git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
4git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
安装完成后再更新一下:
1brew update
检测一下是否有问题:
1brew doctor
我的就检测到一些警告,不过不影响。
为了让Homebrew安装软件时速度更快,需要替换Homebrew-bottles的地址,使用:
1export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
临时替换。如果Mac是终端用的bash,使用
1echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
2source ~/.bash_profile
进行永久替换,如果终端用的是zsh,把bash_profile改为zshrc即可。
方法二
如果上面的镜像还是比较慢,可以再使用下面的命令更换为新的镜像地址mirrors.ustc.edu.cn:
1cd "$(brew --repo)"
2git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
3
4echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
5source ~/.bash_profile
6
7cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
8git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
方法三
可以使用下面的命令设置为国内镜像
1/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
下面为笔者运行情况:
1$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
2
3 开始执行Brew自动安装程序
4 [cunkai.wang@foxmail.com]
5 ['2021-10-01 22:02:07']['10.12']
6 https://zhuanlan.zhihu.com/p/111014448
7
8
9请选择一个下载镜像,例如中科大,输入1回车。
10源有时候不稳定,如果git克隆报错重新运行脚本选择源。cask非必须,有部分人需要。
111、中科大下载源 2、清华大学下载源 3、北京外国语大学下载源 4、腾讯下载源(不推荐) 5、阿里巴巴下载源(不推荐 缺少cask源)
12
13请输入序号: 1
14
15
16 你选择了中国科学技术大学下载源
17
18!!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
19->是否现在开始执行脚本(N/Y) y
20
21--> 脚本开始执行
22 Mac os设置开机密码方法:
23 (设置开机密码:在左上角苹果图标->系统偏好设置->用户与群组->更改密码)
24 (如果提示This incident will be reported. 在用户与群组中查看是否管理员)
25==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
26请输入开机密码,输入过程不显示,输入完后回车
27Password:
28开始执行
29 ---备份要删除的/usr/local/Homebrew到系统桌面....
30cp: /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/fuse/fuse.pc: No such file or directory
31cp: /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/fuse/osxfuse.pc: No such file or directory
32 ---/usr/local/Homebrew 备份完成
33-> 创建文件夹 /usr/local/Homebrew
34运行代码 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew
35此步骤成功
36运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
37运行代码 ==> /usr/bin/sudo /usr/sbin/chown witton /usr/local/Homebrew
38运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
39 ---备份要删除的/Users/witton/Library/Caches/Homebrew到系统桌面....
40cp: /Users/witton/Library/Caches/Homebrew/Backup/bin/idle3: No such file or directory
41cp: /Users/witton/Library/Caches/Homebrew/Backup/bin/pydoc3: No such file or directory
42cp: /Users/witton/Library/Caches/Homebrew/Backup/bin/python3: No such file or directory
43cp: /Users/witton/Library/Caches/Homebrew/Backup/bin/python3-config: No such file or directory
44cp: /Users/witton/Library/Caches/Homebrew/Backup/lib/pkgconfig/python3.pc: No such file or directory
45cp: /Users/witton/Library/Caches/Homebrew/Backup/share/man/man1/python3.1: No such file or directory
46 ---/Users/witton/Library/Caches/Homebrew 备份完成
47 ---备份要删除的/Users/witton/Library/Logs/Homebrew到系统桌面....
48 ---/Users/witton/Library/Logs/Homebrew 备份完成
49git version 2.14.3 (Apple Git-98)
50
51下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
52==> 克隆Homebrew基本文件
53
54未发现Git代理(属于正常状态)
55Cloning into '/usr/local/Homebrew'...
56remote: Enumerating objects: 201010, done.
57remote: Total 201010 (delta 0), reused 0 (delta 0)
58Receiving objects: 100% (201010/201010), 52.37 MiB | 4.42 MiB/s, done.
59Resolving deltas: 100% (149886/149886), done.
60此步骤成功
61--创建Brew所需要的目录
62运行代码 ==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin/brew
63运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin/brew
64运行代码 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Caskroom
65运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Caskroom
66运行代码 ==> /usr/bin/sudo /usr/sbin/chown witton /usr/local/Caskroom
67运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Caskroom
68运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R witton:admin /usr/local/Homebrew
69运行代码 ==> /usr/bin/sudo /bin/mkdir -p /Users/witton/Library/Caches/Homebrew
70运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/witton/Library/Caches/Homebrew
71运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R witton /Users/witton/Library/Caches/Homebrew
72--依赖目录脚本运行完成
73==> 创建brew的替身
74==> 克隆Homebrew Core
75此处如果显示Password表示需要再次输入开机密码,输入完后回车
76Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
77remote: Enumerating objects: 1048692, done.
78remote: Total 1048692 (delta 0), reused 0 (delta 0)
79Receiving objects: 100% (1048692/1048692), 426.79 MiB | 3.12 MiB/s, done.
80Resolving deltas: 100% (726438/726438), done.
81此步骤成功
82==> 克隆Homebrew Cask 图形化软件
83 此处如果显示Password表示需要再次输入开机密码,输入完后回车
84Password:
85Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
86remote: Enumerating objects: 646355, done.
87remote: Total 646355 (delta 0), reused 0 (delta 0)B | 4.13 MiB/s
88Receiving objects: 100% (646355/646355), 281.75 MiB | 4.09 MiB/s, done.
89Resolving deltas: 100% (461968/461968), done.
90此步骤成功
91==> 克隆Homebrew services 管理服务的启停
92
93Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
94remote: Enumerating objects: 1141, done.
95remote: Total 1141 (delta 0), reused 0 (delta 0), pack-reused 1141
96Receiving objects: 100% (1141/1141), 331.50 KiB | 563.00 KiB/s, done.
97Resolving deltas: 100% (484/484), done.
98此步骤成功
99==> 配置国内镜像源HOMEBREW BOTTLE
100运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /Users/witton/.bash_profile
101运行代码 ==> /usr/bin/sudo /usr/sbin/chown witton /Users/witton/.bash_profile
102运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /Users/witton/.bash_profile
103环境变量写入->/Users/witton/.bash_profile
104此步骤成功
105WARNING: this script is deprecated, please see git-completion.zsh
106compinit:498: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask
107运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
108运行代码 ==> /usr/bin/sudo /usr/sbin/chown witton /usr/local/Homebrew
109运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
110
111==> 安装完成,brew版本
112
113Homebrew 3.2.14-45-gd6eb9ec-dirty
114Homebrew/homebrew-core (git revision 4a7c870b593; last commit 2021-10-01)
115Homebrew/homebrew-cask (git revision f6cb1d8826; last commit 2021-10-01)
116Brew前期配置成功
117检测到你不是最新系统,会有一些报错,请稍等Ruby下载安装;
118
119==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
120######################################################################## 100.0%
121==> Pouring portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
122All user-space services OK, nothing cleaned...
123
124 ==> brew update-reset
125
126==> Fetching /usr/local/Homebrew...
127
128==> Resetting /usr/local/Homebrew...
129Branch master set up to track remote branch master from origin.
130Reset branch 'master'
131Your branch is up-to-date with 'origin/master'.
132
133==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
134
135==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask...
136Branch master set up to track remote branch master from origin.
137Reset branch 'master'
138Your branch is up-to-date with 'origin/master'.
139
140==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
141
142==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
143Branch master set up to track remote branch master from origin.
144Reset branch 'master'
145Your branch is up-to-date with 'origin/master'.
146
147==> Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services...
148
149==> Resetting /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services...
150Branch master set up to track remote branch master from origin.
151Reset branch 'master'
152Your branch is up-to-date with 'origin/master'.
153
154
155 Brew自动安装程序运行完成
156 国内地址已经配置完成
157
158 桌面的Old_Homebrew文件夹,大致看看没有你需要的可以删除。
159
160 初步介绍几个brew命令
161本地软件库列表:brew ls
162查找软件:brew search google(其中google替换为要查找的关键字)
163查看brew版本:brew -v 更新brew版本:brew update
164安装cask软件:brew install --cask firefox 把firefox换成你要安装的
165
166 欢迎右键点击下方地址-打开URL 来给点个赞
167 https://zhuanlan.zhihu.com/p/111014448
168
169 重启终端 或者 运行 source /Users/witton/.bash_profile 否则可能无法使用
参考: https://www.zhihu.com/question/35928898 https://blog.csdn.net/DiyHzp/article/details/90763558 https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/ https://mirrors.tuna.tsinghua.edu.cn/help/homebrew-bottles/
- 原文作者:Witton
- 原文链接:https://wittonbell.github.io/posts/2020/2020-05-09-解决Mac下安装Homebrew慢的问题/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. 进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。