开源安装脚本库:

https://gitee.com/cunkai/HomebrewCN

芯片【Intel】:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

芯片【M1】:

/bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"

具体过程:

adamhuan@adamhuandeMacBook-Pro ~ % /bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"

              开始执行Brew自动安装程序
             [cunkai.wang@foxmail.com]
           [2021-11-19 22:27:37][12.0]
       https://zhuanlan.zhihu.com/p/111014448


请选择一个下载镜像,例如中科大,输入1回车。
源有时候不稳定,如果git克隆报错重新运行脚本选择源。cask非必须,有部分人需要。
1、中科大下载源 2、清华大学下载源 3、北京外国语大学下载源 4、腾讯下载源(不显示下载进度) 5、阿里巴巴下载源(缺少cask源)
请输入序号: 2

    你选择了清华大学下载源

!!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
->是否现在开始执行脚本(N/Y)y

--> 脚本开始执行
==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
(设置开机密码:在左上角苹果图标->系统偏好设置->"用户与群组"->更改密码)
(如果提示This incident will be reported. 在"用户与群组"中查看是否管理员)
请输入开机密码,输入过程不显示,输入完后回车
Password:
开始执行
-> 创建文件夹 /opt/homebrew/Homebrew
此步骤成功
-> 创建文件夹 /opt/homebrew/Caskroom
此步骤成功
-> 创建文件夹 /opt/homebrew/Cellar
此步骤成功
-> 创建文件夹 /opt/homebrew/var/homebrew
此步骤成功
-> 创建文件夹 /opt/homebrew/bin
此步骤成功
-> 创建文件夹 /opt/homebrew/etc
此步骤成功
-> 创建文件夹 /opt/homebrew/include
此步骤成功
-> 创建文件夹 /opt/homebrew/lib
此步骤成功
-> 创建文件夹 /opt/homebrew/sbin
此步骤成功
-> 创建文件夹 /opt/homebrew/share
此步骤成功
-> 创建文件夹 /opt/homebrew/opt
此步骤成功
-> 创建文件夹 /opt/homebrew/share/zsh
此步骤成功
-> 创建文件夹 /opt/homebrew/share/zsh/site-functions
此步骤成功
-> 创建文件夹 /opt/homebrew/var/homebrew/linked
此步骤成功
-> 创建文件夹 /opt/homebrew/Frameworks
此步骤成功
git version 2.30.1 (Apple Git-130)

下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
==> 克隆Homebrew基本文件(32M+)

未发现Git代理(属于正常状态)
Cloning into '/opt/homebrew/Homebrew'...
remote: Enumerating objects: 197437, done.
remote: Counting objects: 100% (197437/197437), done.
remote: Compressing objects: 100% (51362/51362), done.
remote: Total 197437 (delta 146130), reused 191127 (delta 141247)
Receiving objects: 100% (197437/197437), 50.93 MiB | 1006.00 KiB/s, done.
Resolving deltas: 100% (146130/146130), done.
此步骤成功
==> 创建brew的替身
此步骤成功
==> 克隆Homebrew Core(224M+) 
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/opt/homebrew/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1095996, done.
remote: Counting objects: 100% (1095996/1095996), done.
remote: Compressing objects: 100% (358335/358335), done.
remote: Total 1095996 (delta 757442), reused 1064784 (delta 734538)
Receiving objects: 100% (1095996/1095996), 350.57 MiB | 980.00 KiB/s, done.
Resolving deltas: 100% (757442/757442), done.
此步骤成功
==> 克隆Homebrew Cask(248M+) 类似AppStore 
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Password:
Cloning into '/opt/homebrew/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 605124, done.
remote: Counting objects: 100% (605124/605124), done.
remote: Compressing objects: 100% (186657/186657), done.
remote: Total 605124 (delta 428902), reused 590313 (delta 416925)  
Receiving objects: 100% (605124/605124), 253.23 MiB | 2.06 MiB/s, done.
Resolving deltas: 100% (428902/428902), done.
此步骤成功
==> 配置国内镜像源HOMEBREW BOTTLE
此步骤成功

==> 安装完成,brew版本

12.0
brew -v

zsh:363: command not found: brew

    失败 查看下面文章第二部分的常见错误
    https://zhuanlan.zhihu.com/p/111014448
    如果没有解决,把运行脚本过程截图发到 cunkai.wang@foxmail.com --end
    
adamhuan@adamhuandeMacBook-Pro ~ %

可以看到,上面有一个报错【zsh:363: command not found: brew】

解决方法:

先看看Homebrew被安装到了哪里:

adamhuan@adamhuandeMacBook-Pro ~ % ls -ltr /opt 
total 0
drwxr-xr-x  14 root  wheel  448 11 19 22:28 homebrew
adamhuan@adamhuandeMacBook-Pro ~ % ls -ltr /opt/homebrew/bin 
total 0
lrwxr-xr-x  1 root  admin  31 11 19 22:29 brew -> /opt/homebrew/Homebrew/bin/brew
adamhuan@adamhuandeMacBook-Pro ~ % 

配置环境变量:

adamhuan@adamhuandeMacBook-Pro ~ % cat ~/.zshrc 

# HomeBrew
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
# HomeBrew END
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH"
adamhuan@adamhuandeMacBook-Pro ~ % 
adamhuan@adamhuandeMacBook-Pro ~ % source ~/.zshrc 
adamhuan@adamhuandeMacBook-Pro ~ % 

查看Homebrew的版本:

adamhuan@adamhuandeMacBook-Pro ~ % which brew
/opt/homebrew/bin/brew
adamhuan@adamhuandeMacBook-Pro ~ %
adamhuan@adamhuandeMacBook-Pro ~ % brew -v
Homebrew 3.3.4-63-gfaaa980-dirty
Homebrew/homebrew-core (git revision cdc5c482694; last commit 2021-11-19)
Homebrew/homebrew-cask (git revision 0f9df25ec0; last commit 2021-11-19)
adamhuan@adamhuandeMacBook-Pro ~ % 

至此,Homeberw配置完成。


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

隐藏
变装