东林博客

MacOS使用阿里云镜像安装HomeBrew教程

获取install文件并编辑

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

编辑brew_install文件

vim brew_install
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/Homebrew/brew/tarball/master anywhere you like or
# change the value of HOMEBREW_PREFIX.
HOMEBREW_PREFIX = "/usr/local".freeze
HOMEBREW_REPOSITORY = "/usr/local/Homebrew".freeze
HOMEBREW_CACHE = "#{ENV["HOME"]}/Library/Caches/Homebrew".freeze
HOMEBREW_OLD_CACHE = "/Library/Caches/Homebrew".freeze
#BREW_REPO = "https://github.com/Homebrew/brew".freeze
BREW_REPO = "https://mirrors.aliyun.com/homebrew/brew.git".freeze
#CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze
CORE_TAP_REPO = "https://mirrors.aliyun.com/homebrew/homebrew-core.git".freeze

上面其实修改了以下注释的部分:

BREW_REPO = "https://github.com/Homebrew/brew".freeze
CORE_TAP_REPO = "https://github.com/Homebrew/homebrew-core".freeze

修改为:

BREW_REPO = "https://mirrors.aliyun.com/homebrew/brew.git".freeze
CORE_TAP_REPO = "https://mirrors.aliyun.com/homebrew/homebrew-core.git".freeze

修改好之后,按ESC,输入 :wq 保存退出,执行brew_install

/usr/bin/ruby ~/brew_install

执行后会开始安装。安装完成后,需要替换各种源,才能用brew安装各种软件。

1. 替换homebrew默认源

cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

2. 替换homebrew-core源

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

3. 设置 bintray镜像

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles/' >> ~/.bash_profile
source ~/.bash_profile

以上设置成功,就可以使用brew安装各种软件了。

brew install nginx
brew install mysql


{{tip}}