在使用 Homebrew install的过程中,经常会卡在Updating Homebrew...
这个过程中。
1
2
3
4
| vim ~/.zshrc
# 新增一行
export HOMEBREW_NO_AUTO_UPDATE=true
|
1
2
3
| brew install composer
Updating Homebrew...
^C
|
按住 control + c 之后命令行会显示 ^C,就代表已经取消了 Updating Homebrew 操作
大概不到 1 秒钟之后就会去执行我们真正需要的安装操作了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| ~ brew install nginx
Updating Homebrew...
^C==> Installing dependencies for nginx: pcre
==> Installing nginx dependency: pcre
==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/bottles/pcre-8.43.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pcre-8.43.catalina.bottle.tar.gz
🍺 /usr/local/Cellar/pcre/8.43: 204 files, 5.5MB
==> Installing nginx
==> Downloading https://mirrors.aliyun.com/homebrew/homebrew-bottles/bottles/nginx-1.17.6.catalina.bottle.tar.gz
######################################################################## 100.0%
==> Pouring nginx-1.17.6.catalina.bottle.tar.gz
==> Caveats
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
==> Summary
🍺 /usr/local/Cellar/nginx/1.17.6: 25 files, 2MB
==> Caveats
==> nginx
Docroot is: /usr/local/var/www
The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.
nginx will load all files in /usr/local/etc/nginx/servers/.
To have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
|
这个方法是临时的、一次性的
平时我们执行 brew 命令安装软件的时候,跟以下 3 个仓库地址有关:
brew.git
homebrew-core.git
homebrew-bottles
通过以下代码依次将这三个仓库的镜像源更换为不同的国内镜像源(zsh
下)
1
2
3
4
5
6
7
8
9
10
11
12
| # 替换brew.git:
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
# 替换homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
# 替换homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
# 应用生效
brew update
# 删除homebrew-bottles
vi ~/.zshrc
#### 按i进入输入模式,输入模式下删除 HOMEBREW_BOTTLE_DOMAIN 这一行配置,然后按:wq保存并退出
source ~/.zshrc
|
1
2
3
4
5
6
7
8
9
10
11
| # 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
# 应用生效
brew update
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
|
1
2
3
4
5
6
7
8
9
10
11
| # 替换brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替换homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# 应用生效
brew update
# 替换homebrew-bottles(根据镜像地址猜测):
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
|
1
2
3
4
5
6
7
8
9
10
11
| # 替换brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 替换homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 替换homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 应用生效
brew update
# 替换homebrew-bottles:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
|
关于homebrew-bottles
,分为以下两种情况:
【1】bash
用户和zsh
用户的命令不同,以上示例中关于homebrew-bottles
的替换仅适用于zsh
用户。
【2】bash
用户请将配置文件zshrc
换为bash_profile
下面给出清华大学镜像源给出的替换homebrew-bottles
在bash
下的代码,其他以此类推。
1
2
3
4
5
6
| ### 临时替换
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles
### 长期替换
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
|