一、方法一
国内安装Homebrew很慢,可以使用下面的方法:
curl -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也不用新增。
执行下面的命令开始安装:
/usr/bin/ruby brew_install
安装到显示:
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
时,可能会比较慢了,此时中断安装。手动执行:
git 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的地址也改为国内的镜像地址:
cd $(brew --repo)
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
或者:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
git -C "$(brew --repo homebrew/cask-fonts)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
git -C "$(brew --repo homebrew/cask-drivers)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-drivers.git
安装完成后再更新一下:
brew update
检测一下是否有问题:
brew doctor
我的就检测到一些警告,不过不影响。
为了让Homebrew安装软件时速度更快,需要替换Homebrew-bottles的地址,使用:
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
临时替换。如果Mac是终端用的bash,使用
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
进行永久替换,如果终端用的是zsh,把bash_profile改为zshrc即可。
方法二
如果上面的镜像还是比较慢,可以再使用下面的命令更换为新的镜像地址mirrors.ustc.edu.cn:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
方法三
可以使用下面的命令设置为国内镜像
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
下面为笔者运行情况:
$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
开始执行Brew自动安装程序
[cunkai.wang@foxmail.com]
['2021-10-01 22:02:07']['10.12']
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文件夹
请输入开机密码,输入过程不显示,输入完后回车
Password:
开始执行
---备份要删除的/usr/local/Homebrew到系统桌面....
cp: /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/fuse/fuse.pc: No such file or directory
cp: /usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/fuse/osxfuse.pc: No such file or directory
---/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 witton /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
---备份要删除的/Users/witton/Library/Caches/Homebrew到系统桌面....
cp: /Users/witton/Library/Caches/Homebrew/Backup/bin/idle3: No such file or directory
cp: /Users/witton/Library/Caches/Homebrew/Backup/bin/pydoc3: No such file or directory
cp: /Users/witton/Library/Caches/Homebrew/Backup/bin/python3: No such file or directory
cp: /Users/witton/Library/Caches/Homebrew/Backup/bin/python3-config: No such file or directory
cp: /Users/witton/Library/Caches/Homebrew/Backup/lib/pkgconfig/python3.pc: No such file or directory
cp: /Users/witton/Library/Caches/Homebrew/Backup/share/man/man1/python3.1: No such file or directory
---/Users/witton/Library/Caches/Homebrew 备份完成
---备份要删除的/Users/witton/Library/Logs/Homebrew到系统桌面....
---/Users/witton/Library/Logs/Homebrew 备份完成
git version 2.14.3 (Apple Git-98)
下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
==> 克隆Homebrew基本文件
未发现Git代理(属于正常状态)
Cloning into '/usr/local/Homebrew'...
remote: Enumerating objects: 201010, done.
remote: Total 201010 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (201010/201010), 52.37 MiB | 4.42 MiB/s, done.
Resolving deltas: 100% (149886/149886), 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/Caskroom
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Caskroom
运行代码 ==> /usr/bin/sudo /usr/sbin/chown witton /usr/local/Caskroom
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Caskroom
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R witton:admin /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /Users/witton/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/witton/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R witton /Users/witton/Library/Caches/Homebrew
--依赖目录脚本运行完成
==> 创建brew的替身
==> 克隆Homebrew Core
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1048692, done.
remote: Total 1048692 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1048692/1048692), 426.79 MiB | 3.12 MiB/s, done.
Resolving deltas: 100% (726438/726438), done.
此步骤成功
==> 克隆Homebrew Cask 图形化软件
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Password:
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 646355, done.
remote: Total 646355 (delta 0), reused 0 (delta 0)B | 4.13 MiB/s
Receiving objects: 100% (646355/646355), 281.75 MiB | 4.09 MiB/s, done.
Resolving deltas: 100% (461968/461968), done.
此步骤成功
==> 克隆Homebrew services 管理服务的启停
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 1141, done.
remote: Total 1141 (delta 0), reused 0 (delta 0), pack-reused 1141
Receiving objects: 100% (1141/1141), 331.50 KiB | 563.00 KiB/s, done.
Resolving deltas: 100% (484/484), done.
此步骤成功
==> 配置国内镜像源HOMEBREW BOTTLE
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /Users/witton/.bash_profile
运行代码 ==> /usr/bin/sudo /usr/sbin/chown witton /Users/witton/.bash_profile
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /Users/witton/.bash_profile
环境变量写入->/Users/witton/.bash_profile
此步骤成功
WARNING: this script is deprecated, please see git-completion.zsh
compinit:498: no such file or directory: /usr/local/share/zsh/site-functions/_brew_cask
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown witton /usr/local/Homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
==> 安装完成,brew版本
Homebrew 3.2.14-45-gd6eb9ec-dirty
Homebrew/homebrew-core (git revision 4a7c870b593; last commit 2021-10-01)
Homebrew/homebrew-cask (git revision f6cb1d8826; last commit 2021-10-01)
Brew前期配置成功
检测到你不是最新系统,会有一些报错,请稍等Ruby下载安装;
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
==> Pouring portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
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...
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...
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/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/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)