我可能就是闲的很,想搞事情,
Homebrew
的镜像换来换去结果出了很多问题。于是就倒腾了以下,就简单的记录下吧。我不知道其他人有没有遇到过这种情况,反正我是不会把镜像源换来换去了...
下载安装脚本
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install >> ~/Desktop/brew_install.rb && vsc ~/Desktop/brew_install.rb
PS. vsc
是VScode
命令,也可以用其他编辑器打开,比如vim
如果安装了
VS code
,但没有命令,可以执行以下语句。如果觉得vsc
不太适合,也可以换成别的ln -s /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code /usr/local/bin/vsc
修改安装脚本
-
修改上游镜像
找到这一行语句
BREW_REPO = "https://github.com/Homebrew/brew".freeze
替换成以下语句
BREW_REPO = "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git".freeze
PS. 这里采用的是清华大学的
Homebrew
上游镜像,当然你也可以使用其他的国内镜像 -
注释自更新语句
注释前
ohai "Downloading and installing Homebrew..." Dir.chdir HOMEBREW_REPOSITORY do # we do it in four steps to avoid merge errors when reinstalling system "git", "init", "-q" # "git remote add" will fail if the remote is defined in the global config system "git", "config", "remote.origin.url", BREW_REPO system "git", "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*" # ensure we don't munge line endings on checkout system "git", "config", "core.autocrlf", "false" system "git", "fetch", "origin", "master:refs/remotes/origin/master", "--tags", "--force" system "git", "reset", "--hard", "origin/master" system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew" system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force" end
注释后
ohai "Downloading and installing Homebrew..." Dir.chdir HOMEBREW_REPOSITORY do # we do it in four steps to avoid merge errors when reinstalling system "git", "init", "-q" # "git remote add" will fail if the remote is defined in the global config system "git", "config", "remote.origin.url", BREW_REPO system "git", "config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*" # ensure we don't munge line endings on checkout system "git", "config", "core.autocrlf", "false" system "git", "fetch", "origin", "master:refs/remotes/origin/master", "--tags", "--force" system "git", "reset", "--hard", "origin/master" system "ln", "-sf", "#{HOMEBREW_REPOSITORY}/bin/brew", "#{HOMEBREW_PREFIX}/bin/brew" # system "#{HOMEBREW_PREFIX}/bin/brew", "update", "--force" end
开始安装
/usr/bin/ruby ~/Desktop/brew_install.rb
PS. 由于我已经安装成功,无法上传安装成功后的截图
RUBY
Homebrew
对ruby
版本有一定的需求,在不满足的情况下会重新下载,那么这里我们手动下载。如果觉得麻烦也可以直接跳过这一步,反正包也不大
cat /usr/local/Homebrew/Library/Homebrew/cmd/vendor-install.sh | grep mavericks.bottle.tar.gz
如果没有对Homebrew
安装位置进行修改的话,执行以上命令会得到两个url
链接

直接用第二个链接去下载,下载完成之后移动到以下目录
mv ~/Downloads/portable-ruby-2.6.3.mavericks.bottle.tar.gz ~/Library/Caches/Homebrew
CORE和CASK
-
手动同步
homebrew/core
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git $(brew --repo homebrew/core) --depth 1
-
手动同步
homebrew/cask
git clone https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git $(brew --repo homebrew/cask) --depth 1
初始化和更新
brew update --force
验证镜像
git -C $(brew --repo) remote -v
git -C $(brew --repo homebrew/core) remote -v
git -C $(brew --repo homebrew/cask) remote -v

Homebrew-bottles 镜像
这个比较简单,请点这里
网友评论