mac终端安装Homebrew


张登友,张登友的博客,张登友的网站——


最新方法

更新与2020年4月2日
首先更新源达到加速的效果

# 替换成国内源: 
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git 
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

然后替换Homebrew Bottles源

#zsh用户使用
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc

source ~/.zshrc
#bash用户使用
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile

cd ~
source ~/.bash_profile

brew update

brew 重置恢复默认

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

brew update

1.首先下载安装脚本

cd ~
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> brew_install

2.编辑安装脚本

BREW_REPO = "https://github.com/Homebrew/brew".freeze

更改为

BREW_REPO = "https://mirrors.ustc.edu.cn/brew.git".freeze

并添加

CORE_TAP_REPO = "https://mirrors.ustc.edu.cn/homebrew-core.git".freeze

如图所示

3.运行安装脚本

3.运行命令

/usr/bin/ruby ~/brew_install

4.更改源

#替换homebrew默认源
cd "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git
#替换homebrew-core源
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin git://mirrors.ustc.edu.cn/homebrew-core.git

5.更新

brew update

6.添加配置

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

7.禁用homebrew自动更新

每次安装软件之前都会自动更新,等待时间较长,此处禁用更新

Mac自带终端(bash)输入:

sudo vim ~/.bash_profile

在最后一行添加

export HOMEBREW_NO_AUTO_UPDATE=true

安装了zsh的输入:

sudo vim ~/.zshrc

最后一行添加

export HOMEBREW_NO_AUTO_UPDATE=true

文章作者: 张登友
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 张登友 !
  目录