1. homebrew介绍
1.1 简介
1.2 争议
1.3 数据采集
2. 安装
2.1 Homebrew默认安装目录
2.2 官网安装脚本
2.3 国内安装脚本
2.4 使用科大源安装
3. 修改源
3.1 查看当前源
3.2 修改为阿里源
3.3 替换为清华源
3.4 替换为中科大源
3.5 腾讯源
3.6. 重置为官方源
4. 使用homebrew
5. 软件列表

1. homebrew介绍

1.1 简介

 
Homebrew 是一个免费的开源软件包管理系统,可以简化软件在Apple的 macOS 和 Linux 上的安装。  
包管理器最初由 Max Howell 编写。Homebrew 是 Software Freedom Conservancy 的非营利项目成员,完全由无偿志愿者运营。
安装包含一个 git 存储库,允许用户通过从 GitHub 拉取更新的存储库来更新 Homebrew。 
 

1.2 争议

Homebrew 修改了 /usr/local 的默认权限; 具体来说,模式从 drwxr-xr-x root wheel 更改为 drwxrwxr-x myuser admin。  
安装程序更改了所有文件(不仅仅是目录)的所有权。  一些人认为这是一个主要的安全漏洞。
rwx r-x r-x root wheel
rwx rwx r-x myuser admin
用户   其他
用户
用户  
  所属组   所属组
 

1.3 数据采集

Homebrew 通过 Google Analytics 收集安装、构建错误和操作系统版本统计信息。 
可以使用命令 brew analytics off 选择退出。 
用户可以在 Homebrew 网站上查看过去 30、90 和 365 天的分析数据。
 

2. 安装

 

2.1 Homebrew默认安装目录

  • macOS (Intel) 的 /usr/local
  • macOS (Apple Silicon 即M1) 的 /opt/homebrew 
  • Linux 的 /home/linuxbrew/.linuxbrew
 

2.2 官网安装脚本

将官网提供的脚本,如下,复制到终端执行即可。
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
 
安装文档和手册页
 

2.3 国内安装脚本

使用以上官网脚本安装很可能会非常慢,直到失败... 如下连接可以直接在浏览器里打开安装脚本文件,里面很多提示和注释都是中文的。
下载并执行安装脚本
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
 

2.4 使用科大源安装

a) 首先在命令行运行如下几条命令设置环境变量:
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git" 
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git" 
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles" 
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
b1) 之后在命令行运行 Homebrew 安装脚本:
/bin/bash -c "$(curl -fsSL https://github.com/Homebrew/install/raw/HEAD/install.sh)"
b2) 初次安装 Homebrew / Linuxbrew 时,如果无法下载安装脚本(上面b1步骤失败),可以使用科大每日同步的安装脚本文件。
/bin/bash -c "$(curl -fsSL https://mirrors.ustc.edu.cn/misc/brew-install.sh)"
 

3. 修改源

Mac 下 brew 切换为国内源
 

3.1 查看当前源

 % cd "$(brew --repo)" && git remote -v               
 origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git (fetch) 
 origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git (push)  
 % cd "$(brew --repo homebrew/core)" && git remote -v 
 origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (fetch) 
 origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git (push)
 

3.2 修改为阿里源

$ git -C "$(brew --repo)" remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git 
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
 
# zsh 替换 brew bintray 镜像 
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc 
$ source ~/.zshrc
# bash 替换 brew bintray 镜像 
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile 
$ source ~/.bash_profile
# 刷新源 
$ brew update
 

3.3 替换为清华源

# 替换各个源 
$ 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 
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# zsh 替换 brew bintray 镜像 
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc 
$ source ~/.zshrc
# bash 替换 brew bintray 镜像 
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile 
$ source ~/.bash_profile
# 刷新源 
$ brew update
 

3.4 替换为中科大源

# 替换各个源 
$ git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git 
$ git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git 
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# zsh 替换 brew bintray 镜像 
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc 
$ source ~/.zshrc
# bash 替换 brew bintray 镜像 
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile 
$ source ~/.bash_profile
# 刷新源 
$ brew update
 

3.5 腾讯源

cd "$(brew --repo)" 
git remote set-url origin https://mirrors.cloud.tencent.com/homebrew/brew.git 
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" 
git remote set-url origin https://mirrors.cloud.tencent.com/homebrew/homebrew-core.git 
brew update
 

3.6 重置为官方源

$ 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 
$ git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask
# zsh 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置 
$ vi ~/.zshrc 
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# bash 注释掉 HOMEBREW_BOTTLE_DOMAIN 配置 
$ vi ~/.bash_profile 
# export HOMEBREW_BOTTLE_DOMAIN=xxxxxxxxx
# 刷新源 
$ brew update
 
查看当前源
% cd "$(brew --repo)" && git remote -v 
 origin https://github.com/Homebrew/brew.git (fetch) 
 origin https://github.com/Homebrew/brew.git (push) 
% cd "$(brew --repo homebrew/core)" && git remote -v 
 origin https://github.com/Homebrew/homebrew-core.git (fetch) 
 origin https://github.com/Homebrew/homebrew-core.git (push) 
% cd "$(brew --repo homebrew/cask)" && git remote -v 
 origin https://github.com/Homebrew/homebrew-cask (fetch) 
 origin https://github.com/Homebrew/homebrew-cask (push)
 
% cat ~/.zshrc  
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles 
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles 
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles 
# export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.cloud.tencent.com/homebrew-bottles 
# export HOMEBREW_BOTTLE_DOMAIN=''
 

4. 使用homebrew

获取帮助 % brew help
搜索软件包 brew search TEXT|/REGEX/
查看软件包信息 brew info [FORMULA|CASK...]
安装软件包 brew install FORMULA|CASK...
更新 Homebrew brew update
查看那些已安装的程序需要更新 brew outdated
不带参数,升级所有软件包 brew upgrade [FORMULA|CASK...]
升级指定软件包 brew upgrade [package]
卸载软件包 brew uninstall FORMULA|CASK...
列出已安装的软件包列表 brew list [FORMULA|CASK...]
列出软件包的依赖关系 brew deps [package]
清除过时软件包 brew cleanup
-n 查看可清理的旧版本包,不执行实际操作 brew cleanup -n
清理指定包的旧版本 brew cleanup [package]
配置信息 brew config
检查系统是否存在问题 brew doctor
安装显示debug信息 brew install --verbose --debug FORMULA|CASK
不带参数的话,
将会列出当前已经tapped 的仓库:
% brew tap
homebrew/cask
homebrew/core
homebrew/services
 

5. 软件列表

核心仓库软件列表,和图形界面软件列表
下面是按照统计下载最多的软件排列
 
顺便列举一些常用软件
libreoffice, blender, vlc, virtualbox, microsoft-office, qbittorrent, telegram-desktop, vmware-fusion, kindle, qq, 
google-earth-pro, v2rayx, notion, crossover, gimp, github, telegram, gdisk, youtube-downloader, ccleaner, ffmpeg...