mac上homebrew最新国内源安装方法

  |  

官网的安装方法

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

Homebrew国内源安装

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

由于访问https://raw.githubusercontent.com/Homebrew/install/master/install.sh需要翻墙 没有翻墙工具的可以访问我已经下载好的文件

1
2
cd ~
curl -fsSL https://gitee.com/w-klover/mac_software_package/blob/master/install.sh >> brew_install

在终端中用curl复制地址内容,或者直接从浏览器上输入地址后复制内容,然后修改BREW_REPO的值

1
2
#BREW_REPO="https://github.com/Homebrew/brew"
BREW_REPO="git://mirrors.ustc.edu.cn/brew.git"

修改保存后,执行以下命令后会快速进行安装

1
/bin/bash brew_install

安装的中间会卡在(或者github拉取失败)

Cloning into ‘/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core’…

这时候直接Ctrl+C结束,通过ustc的源进行配置

1
2
3
mkdir -p /usr/local/Homebrew/Library/Taps/homebrew/
cd /usr/local/Homebrew/Library/Taps/homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-core.git

配置完成后终端输入brew help显示帮助信息则说明安装成功,如果提示失败请检查/usr/local/bin下是否有brew,有的话添加环境变量即可(在/usr/local下可以不配置)

Homebrew Cask安装

Homebrew Cask需要用homebrew进行安装,同样建议修改homebrew的镜像源为ustc源(或者国内其他源)。如果是按照上面的方法安装的homebrew,镜像源应该已经是ustc的源,用下面的命令查看。

1
2
3
4
5
6
# 查看brew镜像源
git -C "$(brew --repo)" remote -v
# 查看homebrew-core镜像源
git -C "$(brew --repo homebrew/core)" remote -v
# 查看homebrew-cask镜像源(需要安装后才能查看, 可以跳过)
git -C "$(brew --repo homebrew/cask)" remote -v

如果是https://github.com/Homebrew/brew.git的源,需要进行修改:

1
2
3
4
5
6
7
8
# 修改brew镜像源
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 修改homebrew-core镜像源
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 修改homebrew-cask镜像源(需要安装后才能修改,可以跳过)
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
# 更新
brew update

顺便附上恢复源的地址:

1
2
3
4
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.git
brew update

修改源之后,进行安装Homebrew Cask,输入:

1
brew install brew-cask-completion

安装完成后输入brew cask help测试,如果出现一下内容并卡住(可以跳过)

1
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...

同样的方法,通过ustc的源进行配置

1
2
cd /usr/local/Homebrew/Library/Taps/homebrew
git clone https://mirrors.ustc.edu.cn/homebrew-cask.git

再输入brew cask help测试,应该就会显示帮助信息,接着按照上面的方法修改homebrew-cask镜像源即可。

参考:
homebrew最新国内源安装方法(2020年3月)

文章目录
  1. 1. 官网的安装方法
  2. 2. Homebrew国内源安装
    1. 2.1. 在终端中用curl复制地址内容,或者直接从浏览器上输入地址后复制内容,然后修改BREW_REPO的值
    2. 2.2. 修改保存后,执行以下命令后会快速进行安装
    3. 2.3. 安装的中间会卡在(或者github拉取失败)
    4. 2.4. 这时候直接Ctrl+C结束,通过ustc的源进行配置
  3. 3. Homebrew Cask安装