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

前言

因为一些原因卸载了homebrew,但是用官网的安装方法很慢且容易中断,想用国内的源进行安装。网上大部分的方法都是

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

然后修改源后,用ruby进行安装。但是这个地址已经被“取缔”了,在浏览器输入这个地址显示以下内容:

#!/usr/bin/ruby

STDERR.print <<~EOS
  Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in
  Bash. Please migrate to the following command:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

EOS

Kernel.exec "/bin/bash", "-c", '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"'

Homebrew国内源安装

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

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

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

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

/bin/bash brew_install

安装的中间会卡在

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

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

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,有的话添加环境变量即可

Homebrew Cask安装

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

# 查看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的源,需要进行修改:

# 修改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

顺便附上恢复源的地址:

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

修改源之后,输入:

brew install brew-cask-completion

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

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

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

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

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

发布了84 篇原创文章 · 获赞 20 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/WizardtoH/article/details/104744008